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

Zephir: read static property

As i see the zephir for the current time not supports the Late Static Bindings for static properties. So i try to use inject C-macros to zephir... and got exception.

namespace Igor;

class Abc
{
   public static myproperty = "Hello ABC";

   public static function printer()
   {
        var className, value = null;
        let className = get_called_class();

        %{
            zephir_read_static_property(&value, Z_STRVAL_P(className), Z_STRLEN_P(className), SS("myproperty") TSRMLS_CC);
        }%

        echo value;
   }
}

then i try to direct read static property from php. It's OK.

echo Igor\Abc::$myproperty; // OK

when i call printer... i get error.

 Igor\Abc::printer(); // FAIL

error:

*PHP Fatal error:  Access to undeclared static property: Igor\Abc::$myproperty in ....*

So i can't Late Static Bindings for properties with C-injections TOO. :(

my extended class:


class SomeTest extends \Igor\Abc
{
    public static $myproperty = "Hello TEST";
}

\Igor\Abc::printer(); // Hello ABC
SomeTest::printer(); // Hello TEST

Have ideas?



98.9k
Accepted
answer

Hello, you can better post this question in the Zephir forum: https://forum.zephir-lang.com/

In my tool php-to-c-ext, i find a way to make it work, not in zephir level,but in php level.

https://github.com/jimthunderbird/php-to-c-extension#example-11

For me, late static binding, trait... all are suggars feature but not too hard to fullfil.