Bug #69198 [NEW]: Compact function generate array with length but no content
| From: | jrbasso at gmail dot com | Date: | Sat, 07 Mar 2015 05:17:50 +0000 |
| Subject: | Bug #69198 [NEW]: Compact function generate array with length but no content | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-191228@lists.php.net to get a copy of this message | ||
From: jrbasso at gmail dot com
Operating system: Any
PHP version: master-Git-2015-03-07 (Git)
Package: Arrays related
Bug Type: Bug
Bug description:Compact function generate array with length but no content
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 bug report at https://bugs.php.net/bug.php?id=69198&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69198&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69198&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69198&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69198&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69198&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69198&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69198&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69198&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69198&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69198&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69198&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69198&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69198&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69198&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69198&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69198&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69198&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69198&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69198&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69198&r=mysqlcfg