|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-03-07 07:49 UTC] laruence@php.net
-Assigned To:
+Assigned To: Laruence
[2015-03-07 08:49 UTC] laruence@php.net
[2015-03-07 08:49 UTC] laruence@php.net
-Status: Assigned
+Status: Closed
[2016-07-20 11:39 UTC] davey@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Sun Feb 08 12:00:02 2026 UTC |
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)