|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2019-05-22 22:51 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
-Package: PHP Language Specification
+Package: *General Issues
[2019-05-22 22:51 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 16:00:01 2025 UTC |
Description: ------------ php -v PHP 7.1.23 (cli) (built: Feb 22 2019 22:08:13) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies ---- Created an object with a protected property Created a magic get "__get($name) { return $this->name; }" Assigned my variable a value within the class (in correct scope) When testing if variable is empty outside of object scope it incorrectly returns true for emptyness Test script: --------------- ``` var_dump($obj->var, empty($obj->var)); // Outputs: // $obj->var = "something" // empty($obj-<var) = true But it will work if I pre-retrieve the variable. $val = $obj->var var_dump($var, empty($var)); // Outputs: // $obj->var = "something" // empty($obj-<var) = false ``` Expected result: ---------------- empty on protected variable with a getter should resolve the getter first, then test emptyness Actual result: -------------- empty call on a protected $obj->var - with a magic __get - returns true even if variable is not empty