Skip to content

Instantly share code, notes, and snippets.

@MarceauKa
Last active August 21, 2019 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarceauKa/21216e47d643daeed0c58954db70e3cf to your computer and use it in GitHub Desktop.
Save MarceauKa/21216e47d643daeed0c58954db70e3cf to your computer and use it in GitHub Desktop.
Test empty on PHP magic properties
<?php
class Foo
{
public function __get($name)
{
return 'foo';
}
}
class Bar
{
public function __get($name)
{
return 'bar';
}
public function __isset($name)
{
return true;
}
}
$foo = new Foo();
$bar = new Bar();
var_dump($foo->foo, empty($foo->foo));
// => foo, true
var_dump($bar->bar, empty($bar->bar));
// => bar, false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment