Bug #78443 [NEW]: Trying to create own isset/notempty function creates keys by ref
| From: | 6562680 at gmail dot com | Date: | Thu, 22 Aug 2019 10:58:55 +0000 |
| Subject: | Bug #78443 [NEW]: Trying to create own isset/notempty function creates keys by ref | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-222363@lists.php.net to get a copy of this message | ||
From: 6562680 at gmail dot com
Operating system: Win10
PHP version: 7.2.21
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Trying to create own isset/notempty function creates keys by ref
Description:
------------
When you pass undefined key by reference, the key will be created and
filled with null value.
So you need manually remove these key or choose not to write own isset
functions.
As an attention, you cannot remove these key inside function you pass
key, you should unset it manually at same level you calling own isset.
Test script:
---------------
<?php
// declare
function notempty(&$test, &$result = null)
{
if (! (is_null($test)
|| ('' === $test)
|| (is_float($test) && is_nan($test))
)) {
$result = $test;
}
return isset($result);
}
// run
$arr = [0];
if (notempty($arr[1], $result)) dosomething($result);
var_dump($arr); // wtf, [0,null]
Expected result:
----------------
Auto remove created keys or just really "check" keys before create
it...
Not sure its possible in C
--
Edit bug report at https://bugs.php.net/bug.php?id=78443&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78443&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78443&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78443&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78443&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78443&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78443&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78443&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78443&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78443&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78443&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78443&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78443&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78443&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78443&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78443&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78443&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78443&r=mysqlcfg