fluteofliar Posted July 2, 2010 Share Posted July 2, 2010 In php,AFAIK dollarsign($) is part of variable thatswhy we always variable using this sign........ Now,whats wrong when i use the above defination while accessing a member variable of a class using object, for instance <?php class hello { public $a="php seems sometime illogical"; function _construct() { echo "howz your php experience?"; } } $obj=new hello(); $obj->a;//this works fine $ob->$a;//error::can,t acess empty property? 2)does function are define at the point they call in php? why its necessary to call inner function first before outer function in nested function Quote Link to comment https://forums.phpfreaks.com/topic/206503-classesfunction/ Share on other sites More sharing options...
Alex Posted July 2, 2010 Share Posted July 2, 2010 In that context $a has no value. So you're trying to access a property with a null name, which obviously doesn't exist. You could however do this: $a = 'a'; $ob->$a; When calling the property of a class you just don't use the dollar sign in front of the variable name, that's just how it is. Quote Link to comment https://forums.phpfreaks.com/topic/206503-classesfunction/#findComment-1080174 Share on other sites More sharing options...
fluteofliar Posted July 2, 2010 Author Share Posted July 2, 2010 In that context $a has no value. So you're trying to access a property with a null name, which obviously doesn't exist. You could however do this: $a has value but while accessing it like obj->$a ... it means we are trying to acess the property of object which is refer as $$a inside the object but the property $($a) is empty....well thankz mate for taking pain to reply my quest Quote Link to comment https://forums.phpfreaks.com/topic/206503-classesfunction/#findComment-1080193 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.