you can do this only with a not-so nice hack. essentially you have to
manually search the active symbol table stack for a zval * which equals your
variable. zend_hash_find wont help you, since you're doing a "reverse"
lookup. so the process is something like (totally OTTOMH)
HashTable *table = EG(active_symbol_table);
char *name_im_looking_for = NULL;
while (table && !name_im_looking_for) {
if (name_im_looking_for = find_name(table, zval
*zval_ptr_im_looking_for)) break;
table = get_prev_symbol_table(); /* you're on your own here - i have
no idea how to do this*/
}
static char *find_name(HashTable * table, zval *zval_ptr_im_looking_for)
{
zval **entry;
zend_hash_internal_pointer_reset(table);
while (zend_hash_get_current_data( hash, (void**)&entry) == SUCCESS) {
if (*entry = zval_ptr_im_looking_for) {
char *string_key;
ulong num_key, key_len;
if (HASH_KEY_IS_STRING ==
zend_hash_get_current_key_ex(hash, &string_key, &key_len, &num_key, 0,
NULL)) {
return string_key:
}
}
zend_hash_move_forward(hash);
} /* while */
return NULL;
}
----- Original Message -----
From: Klaus Reimer <[EMAIL PROTECTED]>
Newsgroups: php.dev
To: <[EMAIL PROTECTED]>
Sent: Monday, March 04, 2002 3:11 PM
Subject: Get object name
> Hi,
>
> I need to acces the name of an object in a class method written in C. How
can
> I do this? Example:
>
> I have the following PHP code
>
> $Test=new CMyClass();
> $Test->print_obj_name();
>
> and I have the following print_obj_name()-method written in C:
>
> ZEND_NAMED_FUNCTION(cmyclass_print_obj_name) {
> zend_printf("%s\n",doSomethingMagic());
> }
>
> How can I do the doSomethingMagic() part so my method prints the object
name
> ("Test")? I can access the CLASS name with
>
> getThis()->value.obj.ce->name
>
> but I need the variable name of the class instance ("Test" in this case).
How
> can I do this?
>
> --
> Bye, K <http://www.ailis.de/~k/>
> [A735 47EC D87B 1F15 C1E9 53D3 AA03 6173 A723 E391]
> (Finger [EMAIL PROTECTED] to get public key)
Klaus Reimer <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED].;
> Hi,
>
> I need to acces the name of an object in a class method written in C. How
can
> I do this? Example:
>
> I have the following PHP code
>
> $Test=new CMyClass();
> $Test->print_obj_name();
>
> and I have the following print_obj_name()-method written in C:
>
> ZEND_NAMED_FUNCTION(cmyclass_print_obj_name) {
> zend_printf("%s\n",doSomethingMagic());
> }
>
> How can I do the doSomethingMagic() part so my method prints the object
name
> ("Test")? I can access the CLASS name with
>
> getThis()->value.obj.ce->name
>
> but I need the variable name of the class instance ("Test" in this case).
How
> can I do this?
>
> --
> Bye, K <http://www.ailis.de/~k/>
> [A735 47EC D87B 1F15 C1E9 53D3 AA03 6173 A723 E391]
> (Finger [EMAIL PROTECTED] to get public key)
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php