Hello all.
I am attempting to convert one of my extensions to OOP.
I have a class entry and (I think) I've instantiated an instance of it
within RINIT().
What I haven't been able to do is add a private property to it.
I have the Goleman book and followed the information on pages 148 and 149,
to no avail. The book says to call zend_mangle_prooperty_name() specifying
the class name as the class name argument.
It always fails with "Could not startup."
Stepping through with the debugger I find:
- zend_mangle_property_name() has worked as described in the book. The
property name is \0class\0prop\0. - add_property_double_ex() fails. Actually, the failure is in
_zend_property_info() when it explicitly checks the first character of the
passed property name for a null and fails if it is.
Searching lxr.php.net hasn't helped so far.
Suggestions or a pointer to code that is actually doing this would be great.
By the way, I'm using PHP 5.2.8.
Thanks,
Dave
David,
I personally have not read that book, as I actually heard pertaining
to objects ( where I too have had some issues ) it wasn't really a
terrific reference. Though if this is not the case, I would love to hear
otherwise..
I don't know if this is the "right" way, but a way to go about doing
what you want can be done in the PHP_MINIT_FUNCTION() with something like
zend_declare_property_string(zend_class_entry* ce, char* name, int
name_length, char* value, ZEND_ACC_PRIVATE);
Matthew C. Rice
David M. Patterson wrote:
Hello all.
I am attempting to convert one of my extensions to OOP.
I have a class entry and (I think) I've instantiated an instance of it
within RINIT().
What I haven't been able to do is add a private property to it.I have the Goleman book and followed the information on pages 148 and 149,
to no avail. The book says to call zend_mangle_prooperty_name() specifying
the class name as the class name argument.
It always fails with "Could not startup."
Stepping through with the debugger I find:
- zend_mangle_property_name() has worked as described in the book. The
property name is \0class\0prop\0.- add_property_double_ex() fails. Actually, the failure is in
_zend_property_info() when it explicitly checks the first character of the
passed property name for a null and fails if it is.Searching lxr.php.net hasn't helped so far.
Suggestions or a pointer to code that is actually doing this would be great.
By the way, I'm using PHP 5.2.8.Thanks,
Dave
David,
I personally have not read that book, as I actually heard pertaining to
objects ( where I too have had some issues ) it wasn't really a terrific
reference. Though if this is not the case, I would love to hear otherwise..
i found the oop section a bit lacking. one of the main issues is that the
chapters are titled "php4 objects", "php5 objects", but really overall
material is spread between the two chapters. like the section "working with
instances" in the php4 objects chapter. where was its counterpart in the
php5 objects chapter? what you begin to realize is a lot of the things are
exactly the same, but i thought at least the organization was a bit awkward.
also, im not sure if when zend_call_method and its variants appeared, i
suspect after the books publication perhaps. that seems to be the way to
go, calling class/object methods. the book illustrates call_user_function()
which by comparison is really painful in working w/ objects imo.
all-in-all though id say the book is solid. ive been able to accomplish
everything ive wanted so far with my first extension. i dunno, ive not
worked with a lot of C api's so far, but i think id probly have struggled
getting started w/o the book.
-nathan