Doc #79675 [NEW]: Incorrect docs for array_key_exists opcode
| From: | paul at namepros dot com | Date: | Thu, 04 Jun 2020 15:23:58 +0000 |
| Subject: | Doc #79675 [NEW]: Incorrect docs for array_key_exists opcode | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-17632@lists.php.net to get a copy of this message | ||
From: paul at namepros dot com
Operating system: Linux 5.4.0
PHP version: 7.4.6
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:Incorrect docs for array_key_exists opcode
Description:
------------
---
From manual page: https://php.net/migration74.other-changes
---
On the aforementioned manual page, I read the following:
> A specialized VM opcode for the array_key_exists() function has been
added, which improves performance of this function if it can be
statically resolved. In namespaced code, this may require writing
\array_key_exists() or explicitly importing the function.
This confirmed my assumption that
use array_key_exists; should be a
valid way to ensure that this new optimization is utilized in namespaced
code. However, I was surprised to find that it doesn't seem to work
according to VLD. Here's namespace-less code:
% php -dvld.active=1 -dvld.execute=0 -r 'array_key_exists(1, []);'
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename: Command line code
function name: (null)
number of ops: 3
compiled vars: none
line #* E I O op fetch ext
return operands
-------------------------------------------------------------------------------------
1 0 E > ARRAY_KEY_EXISTS ~0
1, <array>
1 FREE
~0
2 > RETURN
null
branch: # 0; line: 1- 1; sop: 0; eop: 2; out0: -2
path #1: 0,
But here's what I get with a namespaced version with `use
array_key_exists;`:
% php -dvld.active=1 -dvld.execute=0 -r 'namespace a; use
array_key_exists; array_key_exists(1, []);'
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename: Command line code
function name: (null)
number of ops: 5
compiled vars: none
line #* E I O op fetch ext
return operands
-------------------------------------------------------------------------------------
1 0 E > INIT_NS_FCALL_BY_NAME
'a%5Carray_key_exists'
1 SEND_VAL_EX
1
2 SEND_VAL_EX
<array>
3 DO_FCALL 0
4 > RETURN
null
branch: # 0; line: 1- 1; sop: 0; eop: 4; out0: -2
path #1: 0,
Not what I expected, but
https://www.php.net/manual/en/language.namespaces.faq.php#language.namespaces.faq.shortname2
seems to confirm that this is the expected behavior. The only way to
optimize function calls like array_key_exists and is_array in
namespaced code appears to be to use the fully qualified name, e.g.
\array_key_exists.
Test script:
---------------
<?php
namespace a;
use array_key_exists;
array_key_exists(1, []);
--
Edit bug report at https://bugs.php.net/bug.php?id=79675&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79675&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79675&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79675&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79675&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79675&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79675&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79675&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79675&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79675&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79675&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79675&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79675&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79675&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79675&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79675&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79675&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79675&r=mysqlcfg