php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69198 Compact function generate array with length but no content
Submitted: 2015-03-07 05:17 UTC Modified: 2015-03-07 07:49 UTC
From: jrbasso at gmail dot com Assigned: Laruence (profile)
Status: Closed Package: Arrays related
PHP Version: master-Git-2015-03-07 (Git) OS: Any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jrbasso at gmail dot com
New email:
PHP Version: OS:

 

 [2015-03-07 05:17 UTC] 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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-07 07:49 UTC] laruence@php.net
-Assigned To: +Assigned To: Laruence
 [2015-03-07 08:49 UTC] laruence@php.net
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)
 [2015-03-07 08:49 UTC] laruence@php.net
-Status: Assigned +Status: Closed
 [2016-07-20 11:39 UTC] davey@php.net
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)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 23 05:01:31 2024 UTC