Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will isset() trigger __get and why?

Tags:

php

isset

class a {
   function __get($property){...}
}

$obj = new a();
var_dump(isset($obj->newproperty));

Seems the answer is nope but why?

like image 393
ORM Avatar asked Feb 21 '10 18:02

ORM


1 Answers

Because it checks __isset rather than retrieving it using __get.

It is a much better option to call __isset, as there is no standard on what is empty. Maybe in the context of the class null is an acceptable value. You could also have a class that if the member didn't exist, it returned a new empty object, which would break isset($myObj->item) as in that case it would always return true.

like image 175
Yacoby Avatar answered Oct 03 '22 03:10

Yacoby