Bug #69198 [Asn->Csd]: Compact function generate array with length but no content

From: Date: Sat, 07 Mar 2015 08:49:30 +0000
Subject: Bug #69198 [Asn->Csd]: Compact function generate array with length but no content
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191230@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69198&edit=1 ID: 69198 Updated by: laruence@php.net Reported by: jrbasso at gmail dot com Summary: Compact function generate array with length but no content -Status: Assigned +Status: Closed Type: Bug Package: Arrays related Operating System: Any PHP Version: master-Git-2015-03-07 (Git) Assigned To: Laruence Block user comment: N Private report: N New Comment: Automatic comment on behalf of laruence Revision: http://git.php.net/?p=php-src.git;a=commit;h=28b408a242f66976adf736651ea559340ffc5483 Log: Fixed bug #69198 (Compact function generate array with length but no content) Previous Comments: ------------------------------------------------------------------------ [2015-03-07 05:17:49] jrbasso at gmail dot com Description: ------------ When using the compact function with some variable that is defined on the code but not defined at the moment of the function call cause the generation of an array with length but no content. Doing a regular compact call to a name that doesn't exist but also never attempted to define in the same scope doesn't cause the issue. ie, a regular call to compact('foo') works fine if $foo is not defined or defined conditionally in the same scope. You can check the compact working when the variable is not on the scope: http://3v4l.org/k6bt1 And here is an example when it is defined on the scope, but conditionally will never be called: http://3v4l.org/9Z3aP Test script: --------------- if (false) { $willNeverBeDefined = true; } $result = compact('willNeverBeDefined'); var_dump($result, empty($result), $result === array()); Expected result: ---------------- array(0) { } bool(true) bool(true) Actual result: -------------- array(1) { } bool(false) bool(false) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69198&edit=1

« previous php.bugs (#191230) next »