genericnumber1 Posted December 17, 2006 Share Posted December 17, 2006 Is there a way to get the variable name of the current instance of an object?I know it can be done by something like this...[code=php:0]<?phpclass foo { public $instanceVar; public function __construct($var){ $this->instanceVar = $var; }}$bar = new foo('bar');echo $bar->instanceVar;?>[/code]but is there some other way? like... a function that can be called inside the object? It's not critical that I know, just something that's made me curious. Link to comment https://forums.phpfreaks.com/topic/31030-getting-an-objects-variable/ Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 [quote]but is there some other way?[/quote]Nope. Why would you need it? It doesn't exist within the class, that is what $this is for. Link to comment https://forums.phpfreaks.com/topic/31030-getting-an-objects-variable/#findComment-143186 Share on other sites More sharing options...
genericnumber1 Posted December 18, 2006 Author Share Posted December 18, 2006 in case it needed to be passed to a different class perhaps? :X Oh well it's cleaner to pass it by reference outside the class anyways. Link to comment https://forums.phpfreaks.com/topic/31030-getting-an-objects-variable/#findComment-143223 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.