Jaswinder Posted June 12, 2013 Share Posted June 12, 2013 can anyone clear me what is the difference between -> and => ?? when we call method of a class, we use $obj -> method(); can we use this also ??? $obj => method(); and also ,when we assign a value to a variable ( e.g $name ) , we us $obj->name="Smith"; but what this means ?? $obj->$name .. or is it incorrect ?? or am i assigning value of $name to $obj ?? i have seen a working code ... what it means $obj= new name; //name is a classforeach($obj as $var=>$value) Link to comment https://forums.phpfreaks.com/topic/279058-problem-with-dereference-markerpointer/ Share on other sites More sharing options...
kicken Posted June 12, 2013 Share Posted June 12, 2013 can anyone clear me what is the difference between -> and => ??-> is used by to accesses a member of an object (function or property)=> is used by to define a key/value pair. For example: $dtobject = new DateTime('now'); //A new datetime object $dtobject->format('m/d/y'); //Access the format method of $dtobject and execute it. $arr = array( //Define a new array 'somekey' => 'somevalue' //Define a key/value pair to store in that array ); can we use this also ??? $obj => method(); No, likewise you cannot use -> in place of => when dealing with arrays. but what this means ?? $obj->$name .. It is an application of variable-variables. What happens is PHP uses the value of $name as the name of the property to access. Eg: $field = 'firstname'; $obj = new stdClass; $obj->$field = 'kicken'; var_dump($obj->firstname); //Shows 'kicken' because the value was assigned to $obj->firstname i have seen a working code ... what it means $obj= new name; //name is a class foreach($obj as $var=>$value) It loops through all the public properties of $obj and assigns them as a key/value pair to $var (property name [key]) and $value (property value [value]) Link to comment https://forums.phpfreaks.com/topic/279058-problem-with-dereference-markerpointer/#findComment-1435485 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.