Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:40861 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11002 invoked from network); 4 Oct 2008 22:01:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Oct 2008 22:01:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=karpeles@ookoo.org; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=karpeles@ookoo.org; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ookoo.org designates 88.191.88.38 as permitted sender) X-PHP-List-Original-Sender: karpeles@ookoo.org X-Host-Fingerprint: 88.191.88.38 lamune.ookoo.org Linux 2.6 Received: from [88.191.88.38] ([88.191.88.38:36273] helo=Lamune.ookoo.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7C/E8-48736-CB7E7E84 for ; Sat, 04 Oct 2008 18:01:33 -0400 Received: (pmaild 94164 invoked for user karpeles@ookoo.org); Sun, 05 Oct 2008 00:01:27 +0200 Received: from [192.168.0.25] (30.3.207-77.rev.gaoland.net [77.207.3.30]) by Lamune.ookoo.org (phpinetd by MagicalTux ) with SMTP version 1.0; Sun, 05 Oct 2008 00:01:27 +0200 To: internals@lists.php.net Cc: Kuba Wieczorek In-Reply-To: References: Content-Type: text/plain; charset=UTF-8 Organization: ooKoo.org Date: Sun, 05 Oct 2008 00:01:25 +0200 Message-ID: <1223157686.1712.294.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.22.3.1 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] __get() magic method and its use with empty() function. From: karpeles@ookoo.org ("M." =?ISO-8859-1?Q?Karpel=E8s?=) Hello, Le samedi 04 octobre 2008 à 22:59 +0200, Kuba Wieczorek a écrit : > Well, this is a sample code for this: > > header('Content-type: text/plain'); > > class test > { > protected $a; > protected $b = 'test'; > > public function __get($var) > { > return $this->$var; > } > } > > $test = new test; > print 'a: ' . var_export($test->a, true) . ' ' . > var_export(empty($test->a), true) . "\n"; > print 'b: ' . var_export($test->b, true) . ' ' . > var_export(empty($test->b), true) . "\n"; > ?> > > This is the current result: > a: NULL true > b: 'test' true > > The expected one should be: > a: NULL true > b: 'test' false Please implement magic method __isset($var) and try again. You'll see it works fine this way. Did a little test : class test { private $a; private $b = 'foo'; public function __get($var) { echo "__get($var)\n"; return $this->$var; } public function __isset($var) { echo "__isset($var)\n"; return isset($this->$var); } } $t = new test(); var_dump($t->a, empty($t->a)); var_dump($t->b, empty($t->b)); Output : __get(a) __isset(a) NULL bool(true) __get(b) __isset(b) __get(b) string(3) "foo" bool(false) Mark