ZEND2 - Developer's hell

Posted on 2006-11-27 15:35:48 EET.


Recently I had to fix few important issues related to Zend2 engine and midgard-php extension. All issues were relatively easy to fix , but I realized that hell is coming.

some_class::static_method();

Such language construction works fine with PHP4 and with PHP5.
The difference is that with Zend2 ( PHP5 ) 'static_method' must be explicitly defined as zend static method and not as function ( PHP4 ).
Not a big deal, but ZEND_METHOD macro is expecting class name for which static method is implemented. And this simply can not be passed to macro as variable and must be hardcoded. Well, I could be a writer if I would like to write , write and write. I must reserve endless hours to implement midgard-php extension as pure PHP5 one. Hacks, trials and errors, segfaults, hacks, trial end errors... looping. I didn't read Zend2 sources yet and have no idea how ZEND_METHOD is implemented but I expect Zend guys still use sizeof instead of strlen in such macros so what absolutely must be done is to forget about Zend2 API and write own solution when you work with unknown variables.

Another interesting issue is the fact how GObjects ( or GTK ) ones can be implemented for PHP. For PHP5 I experimented with direct pointers arrays, so there were no need to add some magic __res property to PHP5 objects.
Unfortunatelly it fails on bigger loops like:

while(something) {
$var = new some_class();
}

The solution is to only use __res property.

I wonder how it's safe if one can accidentally or explicitly get "forbidden" object by changing object's __res property value. This is a scripting language so fivth object instance will always have __res value = 5. If this is some secret account for example I can easily change my object's __res value to 5 and get object which shouldn't be available for me.

And another interesting thing is memory usage and kind of "optimization".
I almost finished basic midgard_replicator implementation. And mandatory strings duplication makes me frustrated for months. Why the hell I can not reuse string contents and I have to duplicate it over and over?
Why string variable initialized without duplication parameter ( that's from docs ) triggers segfault when variable is destroyed by zend?

I hope I am wrong. And if I am and some Zend developer is reading it, please be so kind and give that magicall url where such issues are very well documented.

Back

Layout Copyright © 2006 Finnish Teleservice Center Ltd Oy - Site Powered by Midgard CMS