note 71184 added to function.empty

From: Date: Wed, 15 Nov 2006 15:14:03 +0000
Subject: note 71184 added to function.empty
Groups: php.notes 
Request: Send a blank email to php-notes+get-119751@lists.php.net to get a copy of this message
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 ---- Server IP: 194.109.193.119 Probable Submitter: 213.84.167.195 ---- Manual Page -- http://www.php.net/manual/en/function.empty.php Edit -- https://master.php.net/note/edit/71184 Del: integrated -- https://master.php.net/note/delete/71184/integrated Del: useless -- https://master.php.net/note/delete/71184/useless Del: bad code -- https://master.php.net/note/delete/71184/bad+code Del: spam -- https://master.php.net/note/delete/71184/spam Del: non-english -- https://master.php.net/note/delete/71184/non-english Del: in docs -- https://master.php.net/note/delete/71184/in+docs Del: other reasons-- https://master.php.net/note/delete/71184 Reject -- https://master.php.net/note/reject/71184 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#119751) next »