- property_exists: documentation ( source)
- var_dump: documentation ( source)
<?php
namespace App {
trait AccessibleProperties
{
public function __isset($property)
{
return property_exists($this, $property);
}
public function __get($property)
{
if (property_exists($this, $property)) {
return $this->$property;
}
}
}
class Foo {
use AccessibleProperties;
protected $a = 'Some value';
}
$foo = new Foo;
$foo->a; // this works: returns 'Some value'
var_dump(isset($foo->a)); // this doesn't work: returns false
}