Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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?



1.2k
Accepted
answer
edited Oct '14

Hey

You can change like this

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

I'm test it , is working. Also you can refer here https://github.com/andresgutierrez/heka/blob/master/kernel/object.h#L96

I dont know why SL working.. what is difference between SL and SS @phalcon

Thanks. It works.



1.8k
edited Oct '14

Those are shortcuts for:

SL(x) = strlen(x)
SS(x) = sizeof(x)

BTW it amazes me how people insist on using Zephir the most dynamical as possible (when this code cannot be optimized at all) instead of use the static features that is optimized



1.2k

ok, Thanks

Those are shortcuts for:

```php SL(x) = strlen(x) SS(x) = sizeof(x) ```

BTW it amazes me how people insist on using Zephir the most dynamical as possible (when this code cannot be optimized at all) instead of use the static features that is optimized

You mean use optimized "static::" for properties? Current time LSB's not working for static properties. Only for static methods. Sure, we can use "self::" for static properties but without LSB :(