Skip to content

Instantly share code, notes, and snippets.

@kneipp
Created September 30, 2015 14:48
Show Gist options
  • Save kneipp/aee5802d08505d605676 to your computer and use it in GitHub Desktop.
Save kneipp/aee5802d08505d605676 to your computer and use it in GitHub Desktop.
php 5.6.13 - testing empty and __get() behavior
<?php
class Xpto
{
protected $a = 'a';
public $b = 'b';
public function __get($key)
{
echo '__get() ';
return $key;
//var_dump($key);
}
}
$obj = new Xpto();
var_dump(empty($obj->a)); #bool(true)
var_dump($obj->a); # __get() string(1) "a"
var_dump(empty($obj->b)); #bool(false)
@kneipp
Copy link
Author

kneipp commented Sep 30, 2015

class Xpto
{
    protected $a = 'a';
    public $b = 'b';
    public function __get($key)
    {
        echo '__get() ';

        return $key;
        //var_dump($key);
    }

    public function __isset($key)
    {
        return $key;
    }
}
$obj = new Xpto();
var_dump(empty($obj->a)); #__get() bool(false) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment