We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

extend phalcon in zephir

Hi,

i'm trying to extend phalcon in zephir, without success. Lets say i have created my own zephir extension wiht own class:

zephir init utils
namespace Utils;

class Greeting extends \Phalcon\Mvc\User\Component {

    public static function say() {
        echo "hello world!";
    }

}

while compiling the following error is thrown.

PHP Fatal error:  Call to undefined method Zephir\ClassDefinitionRuntime::isInternal() in /opt/zephir/Library/ClassDefinition.php on line 833

This error occurs every time when i try ty extend classes of the phalcan framework. Can it be because phalcon and my extension are not in the same directory?

Thanks



58.4k

Hey

Where do you create file in folder ?

Hi Thien,

im make following steps:

cd /opt
git clone https://github.com/phalcon/zephir
... // install zephir
git clone https://github.com/phalcon/cphalcon.git phalcon
cd phalcon
git checkout 2.0.0
cd ..
zephir init utils

after that my folder structure looks like this:

/opt
    phalcon
        ...
        ext
        phalcon
        config.json
        ...
    utils
        ext
        utils
            greeting.zep
        config.json
    zephir

content of the greeting.zep is as described above

cd /opt/utils
zephir build

Error

Warning: Cannot locate class "Phalcon\Mvc\User\Component" when extending class "Utils\Greeting" in /opt/utils/utils/greeting.zep on 3 [nonexistent-class]

    class Greeting extends \Phalcon\Mvc\User\Component {

PHP Fatal error:  Call to undefined method Zephir\ClassDefinitionRuntime::isInternal() in /opt/zephir/Library/ClassDefinition.php on line 833

What is the correct folder structure to make it work? My classes should have own namespace and not of the phalcon framework. Maybe it needs to be configured in the config.json?

Thanks



58.4k

Hi

If you install Phalcon extension before running script it will working

Phalcon 2.0.0b is installed on the server



58.4k

HI

I try this your code like folder above then working

edited Jan '15

Which os is installed on your server? I use debian and will test the same under ubuntu.



58.4k

Hi

I install Phalcon on Fedora 21, and version Phalcon 1.3.4

edited Jan '15

Hi,

your right it works, but only on installations with official compiled packages. If i install Phalcon from source it didn't work, no matter if debian or ubuntu.

The official compiled package for ubuntu does not work with PHP 5.6. The Debian repository is out of date (Phalcon 1.2.3). It would be nice to extend the official compilation how-to, so that works too.

However, thank you Thien!



58.4k
edited Jan '15

Nice, have fun with Phalcon :)

Ok, i found a solution.

https://github.com/phalcon/zephir/issues/304#issuecomment-61341940

quick reference:

  • Install Zephir

  • Install Phalcon 2.0
    cd /opt/
    git clone https://github.com/phalcon/cphalcon
    cd cphalcon
    git checkout 2.0.0
    zephir build --export-classes
  • add to config.json in our extension:
    "external-dependencies": {
        "phalcon": "/opt/cphalcon"
    }