Reputation: 480
I a bit confused here. I need to throw an exception when a value of an object is not set, however it throws my exception regardless of if it is or is not set.
I run
var_dump(isset($this->{$idName}));
var_dump($this->{$idName});
and the results are
bool(false)
string(1) "1"
I would expect the first to be true. Am I missing something obvious?
To clairfy, I am trying to check if the property of the object that is stored in $idName
is set. In this case $idName = "id"
So $this->id
is what I'm checking.
$this->id
will be retrieved from __get()
Upvotes: 1
Views: 28
Reputation: 1907
If this property is private/protected, and if you are trying to access its value directly from outside using $this->property syntax, make sure it's not just comming from your class __get() magic method.
Upvotes: 0
Reputation: 64536
Looks like you're missing the magic __isset()
method.
public function __isset($name)
{
return isset($this->data[$name]);
}
Change according to where you store the data.
From the Manual:
__isset() is triggered by calling isset() or empty() on inaccessible properties.
Upvotes: 2