Page 1 of 1

how can i obtain name of the class instance from its inside

Posted: Fri Apr 08, 2005 12:18 am
by sinasalek
how can i obtain name of the class instance from its inside.

Code: Select all

class TTest
{
   function instance_name()
   {
       echo "instance name : $instance_name";
   }
}

$test=new TTest();
$text->instance_name();

Code: Select all

result :
instance name : test
i searched the web, but i couldn't find any real way.
i just found some programming ways.
1.

Code: Select all

$test=new TTest('test'); //'test' is name of instance
2.

Code: Select all

$test=new TTest();
 $test->instance_name='test';
3.

Code: Select all

$instance='test';
 $$instance=new TTest($instance);
if need somthing like get_class but not for class name, for instance name.
any idea will be appreciate.

how can i obtain name of the class instance from its inside

Posted: Fri Apr 08, 2005 12:34 am
by marike
If your using PHP 5, It looks like you can use the new "Reflection" class to get internal classes. Have a look here.

http://us4.php.net/manual/en/language.o ... ection.php

Looks very cool.

Hope this helps.