note 71184 deleted from function.empty by didou
| From: | didou@php.net | Date: | Sun, 18 May 2008 00:57:05 +0000 |
| Subject: | note 71184 deleted from function.empty by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-139479@lists.php.net to get a copy of this message | ||
Note Submitter: prikkeldraad at gmail dot com
----
The empty function will not work on an attribute of an object when the object uses the __get method.
The following code:
<?php
class Person {
protected $name_;
public function __construct($name) {
$this->name_ = $name;
}
public function __get($name) {
// just return name
return $this->name_;
}
}
class FirstPerson extends Person {
public function __construct() {
parent::__construct('The great cornholio');
}
public function __get($name) {
return parent::__get($name);
}
}
$tgc = new FirstPerson;
print 'Name: '.$tgc->name.'<br />';
if (!empty($tgc->name)) {
print 'Name via getter is not empty';
} else {
print 'Name via getter is empty';
}
?>
Results in:
Name: The great cornholio
Name via getter is empty