Re: [PHP-DEV] Extension help
ok, I have managed to add a member variable, but am having problems when i try to retreive it using zend_find_hash here's the code : for the extension : PHP_FUNCTION(create_object) { ... other stuff add_property_string(return_value,"foo","hello!",1); ... other stuff } PHP_FUNCTION(my_other_function) { zval **tmpString; zval *obj; obj = getThis(); zend_hash_find(obj-value.obj.properties,"foo",sizeof("foo"),(void**)tmpString); convert_to_string_ex(tmpString); zend_printf("foo = %s",tmpString); } that doesn't work :( but in a php script it does : ? $myObject = create_object(); echo $myObject-foo; ? produces "hello!" what am i doing wrong ?! barry On Mon, Mar 19, 2001 at 07:01:44PM -0500, Sterling Hughes wrote: On Mon, 19 Mar 2001, Barry Mitchelson wrote: hey, I'm writing an extension which defines a class. In the constructor, I'd like to create a member variable which I can then access with the other member functions in my extension. In php it would be like : class foo { var $m_bar; function foo() { $this-m_bar = 123; } function a() { return $this-m_bar; } } look at adding it to the value.obj.properties of the class (its a HashTable). -Sterling -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- http://www.theshining.org -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DEV] Extension help
zend_hash_find(obj-value.obj.properties,"foo",sizeof("foo"),(void**)tmpSt ring); You're almost correct, sizeof("foo") should be sizeof("foo")+1 Cheerio, Marc. -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] Extension help
On Tue, Mar 20, 2001 at 03:24:00PM +0100, Marc Boeren wrote: zend_hash_find(obj-value.obj.properties,"foo",sizeof("foo"),(void**)tmpSt ring); You're almost correct, sizeof("foo") should be sizeof("foo")+1 hmm... still not working :( Cheerio, Marc. -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- http://www.theshining.org -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DEV] Extension help
You're almost correct, sizeof("foo") should be sizeof("foo")+1 hmm... still not working :( My fault for not reading on beyond the first typo: zend_printf("foo = %s",tmpString); should probably be zend_printf("foo = %s", (*tmpString)-value.str.val); but I may be wrong on the level of indirection. The zval cannot automagically be put in a %s and treated as a string, you should manually extract the pointer to the actual string. Hope this helps! Cheerio, Marc. (btw, you might have a look at the way the zval struct is set up in the source code) -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] Extension help
On Tue, Mar 20, 2001 at 03:59:29PM +0100, Marc Boeren wrote: You're almost correct, sizeof("foo") should be sizeof("foo")+1 hmm... still not working :( My fault for not reading on beyond the first typo: zend_printf("foo = %s",tmpString); should probably be zend_printf("foo = %s", (*tmpString)-value.str.val); but I may be wrong on the level of indirection. The zval cannot automagically be put in a %s and treated as a string, you should manually extract the pointer to the actual string. even though i did convert_to_string_ex(tmpString) ? Hope this helps! Cheerio, Marc. (btw, you might have a look at the way the zval struct is set up in the source code) -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- http://www.theshining.org -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DEV] Extension help
Hi! even though i did convert_to_string_ex(tmpString) ? You should still do that, but the only thing that really does is set the zval type to IS_STRING, and the value union is set accordingly (instead of e.g. a long in value.lval, you get the value as a string in value.str.val (and the length of the string in value.str.len, excl. terminating 0). So what you have after the conversion is still a zval, but you can now safely use the value.str.val (which is of type char *, as you would expect). Cheerio, Marc. -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] Extension help
BM but I may be wrong on the level of indirection. BM The zval cannot automagically be put in a %s and treated as a string, you BM should manually extract the pointer to the actual string. BM BM even though i did convert_to_string_ex(tmpString) ? The convert_to_string_ex makes tmpString to be sting zval (otherwise you better not access the str.val part at all - there could be a pile of thrash there). That doesn't make tmpString a C string, however - it's still a zval. -- Stanislav Malyshev, Zend Products Engineer [EMAIL PROTECTED] http://www.zend.com/ +972-3-6139665 ext.115 -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] Extension help
On Tue, Mar 20, 2001 at 05:15:58PM +0100, Marc Boeren wrote: BTW, (*tmpString)-value.str.val == Z_STRVAL_PP(tmpString) but the latter looks much nicer :) Granted, but that's what happens if you just examine the code and don't read the documentation :-) is there full documentation of the Zend API - i found the stuff on the zend website to be useful, but didn't cover everything. Cheerio, Marc. -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- http://www.theshining.org -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] Extension help mailing list???
MB If there is, I couldn't find it either. The docs are at http://www.zend.com/apidoc/ -- Stanislav Malyshev, Zend Products Engineer [EMAIL PROTECTED] http://www.zend.com/ +972-3-6139665 ext.115 -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] Extension help
On Tue, Mar 20, 2001 at 06:48:39PM +0200, Stanislav Malyshev wrote: BM is there full documentation of the Zend API - i found the stuff BM on the zend website to be useful, but didn't cover everything. Well, that's the most full one that exists. Eventually, it should be extended to cover the most, but before it happnes, you have the code and the PHP-DEV... yeah, think once i get my extension finally working I may write a tutorial on creating something more advanced than running ext_skel and adding a function - eg, defining a class, using objects etc.. -- Stanislav Malyshev, Zend Products Engineer [EMAIL PROTECTED] http://www.zend.com/ +972-3-6139665 ext.115 -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- http://www.theshining.org -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] Extension help
On Tue, 20 Mar 2001, Barry Mitchelson wrote: ok, I have managed to add a member variable, but am having problems when i try to retreive it using zend_find_hash here's the code : for the extension : PHP_FUNCTION(create_object) { ... other stuff add_property_string(return_value,"foo","hello!",1); ... other stuff } PHP_FUNCTION(my_other_function) { zval **tmpString; zval *obj; obj = getThis(); zend_hash_find(obj-value.obj.properties,"foo",sizeof("foo"),(void**)tmpString); convert_to_string_ex(tmpString); zend_printf("foo = %s",tmpString); } Z_STRVAL_PP(tmpString) in the zend_printf() statement. that doesn't work :( but in a php script it does : ? $myObject = create_object(); echo $myObject-foo; ? produces "hello!" what am i doing wrong ?! barry On Mon, Mar 19, 2001 at 07:01:44PM -0500, Sterling Hughes wrote: On Mon, 19 Mar 2001, Barry Mitchelson wrote: hey, I'm writing an extension which defines a class. In the constructor, I'd like to create a member variable which I can then access with the other member functions in my extension. In php it would be like : class foo { var $m_bar; function foo() { $this-m_bar = 123; } function a() { return $this-m_bar; } } look at adding it to the value.obj.properties of the class (its a HashTable). -Sterling -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] Extension help
On Mon, 19 Mar 2001, Barry Mitchelson wrote: hey, I'm writing an extension which defines a class. In the constructor, I'd like to create a member variable which I can then access with the other member functions in my extension. In php it would be like : class foo { var $m_bar; function foo() { $this-m_bar = 123; } function a() { return $this-m_bar; } } look at adding it to the value.obj.properties of the class (its a HashTable). -Sterling -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]