- property_exists: documentation ( source)
<?php
class Example
{
public $foo;
public function __get($k)
{
echo 'Getting ' . $k;
}
public function __set($k, $v)
{
echo 'Setting ' . $k . ' = ' . $v;
}
protected function _makeProperty()
{
$this->bar = 'baz';
}
public function makeProperty()
{
$this->_makeProperty();
}
}
$e = new Example();
echo (property_exists($e, 'foo') ? 'Yes' : 'No') . PHP_EOL;
echo (property_exists($e, 'bar') ? 'Yes' : 'No') . PHP_EOL;
$e->makeProperty();
echo (property_exists($e, 'foo') ? 'Yes' : 'No') . PHP_EOL;
echo (property_exists($e, 'bar') ? 'Yes' : 'No') . PHP_EOL;
echo $e->bar . PHP_EOL;