The following code:
Resulted in this output:
Creation of dynamic property OCILob::$descriptor is deprecated
https://github.com/doctrine/dbal/runs/6850136105?check_suite_focus=true
But I expected this output instead:
The piece of code that PHP complains about does not write any property directly but calls oci_new_descriptor()
which is supposed to return a new OCILob
instance. I don't feel like I could avoid the deprecation.
PHP 8.2-dev 13479ee
Ubuntu 20.04
We've been encountering regular php-fpm segfaults in production.
Inspecting coredumps revealed gibberish class entries in the interfaces field of the ce of a class named Z\Module\Comment\Orm\CommentObject
, which caused segfaults when copying interfaces over to the interfaces field of the ce of child class Z\Module\Zext\Orm\ZextCommentObject
.
Native backtrace:
#0 0x000055a86a9e586f in do_implement_interface (iface=0x41868fc8, ce=0x7f53332a4da0) at ./Zend/zend_inheritance.c:1288
#1 zend_do_inherit_interfaces (ce=0x7f53332a4da0, iface=<optimized out>, iface=<optimized out>) at ./Zend/zend_inheritance.c:1326
#2 0x000055a86a9ea16e in zend_try_early_bind (ce=0x7f53332a4da0, ce@entry=0x43e5fca0, parent_ce=0x43e67d60, lcname=0x417daa70, delayed_early_binding=delayed_early_binding@entry=0x55a86b5f9f90)
at ./Zend/zend_inheritance.c:3062
#3 0x000055a86a92ec6b in zend_do_delayed_early_binding (op_array=op_array@entry=0x7f531a905000, first_early_binding_opline=<optimized out>) at ./Zend/zend_compile.c:1381
#4 0x00007f533ec49a9b in zend_accel_load_script (persistent_script=persistent_script@entry=0x43e5fa40, from_shared_memory=from_shared_memory@entry=1)
at ./ext/opcache/zend_accelerator_util_funcs.c:255
#5 0x00007f533ec38260 in persistent_compile_file (type=<optimized out>, file_handle=<optimized out>) at ./ext/opcache/ZendAccelerator.c:2247
#6 persistent_compile_file (file_handle=<optimized out>, type=<optimized out>) at ./ext/opcache/ZendAccelerator.c:1957
#7 0x000055a86a9164ad in compile_filename (type=type@entry=2, filename=filename@entry=0x7f533329e0c0) at ./Zend/zend_language_scanner.c:707
#8 0x000055a86a984a86 in zend_include_or_eval (inc_filename_zv=<optimized out>, type=2) at ./Zend/zend_execute.c:4753
#9 0x000055a86a992f8e in ZEND_INCLUDE_OR_EVAL_SPEC_CV_HANDLER () at ./Zend/zend_vm_execute.h:38732
#10 0x000055a86a9b9c95 in execute_ex (ex=0x41868fc8) at ./Zend/zend_vm_execute.h:59146
#11 0x000055a86a9440fc in zend_call_function (fci=<optimized out>, fci_cache=<optimized out>) at ./Zend/zend_execute_API.c:908
#12 0x000055a86a9444cd in zend_call_known_function (fn=0x4344a338, object=<optimized out>, called_scope=<optimized out>, retval_ptr=retval_ptr@entry=0x0, param_count=param_count@entry=1,
params=params@entry=0x7ffc1f850030, named_params=0x0) at ./Zend/zend_execute_API.c:997
#13 0x000055a86a844377 in spl_perform_autoload (class_name=0x417daa30, lc_name=0x7f531a8d6a80) at ./ext/spl/php_spl.c:436
#14 0x000055a86a94338c in zend_lookup_class_ex (name=<optimized out>, key=key@entry=0x0, flags=flags@entry=0) at ./Zend/zend_execute_API.c:1141
#15 0x00007f533ec30df3 in zend_accel_inheritance_cache_get (ce=0x43e67d60, parent=0x435a0830, traits_and_interfaces=0x7ffc1f850120) at ./ext/opcache/ZendAccelerator.c:2317
#16 0x000055a86a9e8612 in zend_do_link_class (ce=ce@entry=0x43e67d60, lc_parent_name=lc_parent_name@entry=0x41716d98, key=0x4181cfa8) at ./Zend/zend_inheritance.c:2783
#17 0x000055a86a92e3e6 in zend_bind_class_in_slot (class_table_slot=<optimized out>, lcname=0x43e8f620, lc_parent_name=0x41716d98) at ./Zend/zend_compile.c:1131
#18 0x000055a86a92e4ac in do_bind_class (lcname=0x43e8f620, lc_parent_name=0x41716d98) at ./Zend/zend_compile.c:1164
#19 0x000055a86a985ca9 in ZEND_DECLARE_CLASS_SPEC_CONST_HANDLER () at ./Zend/zend_vm_execute.h:5335
#20 0x000055a86a9b956f in execute_ex (ex=0x41868fc8) at ./Zend/zend_vm_execute.h:56216
#21 0x000055a86a9440fc in zend_call_function (fci=<optimized out>, fci_cache=<optimized out>) at ./Zend/zend_execute_API.c:908
#22 0x000055a86a9444cd in zend_call_known_function (fn=0x4344a338, object=<optimized out>, called_scope=<optimized out>, retval_ptr=retval_ptr@entry=0x0, param_count=param_count@entry=1,
params=params@entry=0x7ffc1f8506b0, named_params=0x0) at ./Zend/zend_execute_API.c:997
#23 0x000055a86a844377 in spl_perform_autoload (class_name=0x7f531a8d69c0, lc_name=0x7f531a8d6ac0) at ./ext/spl/php_spl.c:436
#24 0x000055a86a94338c in zend_lookup_class_ex (name=<optimized out>, key=key@entry=0x0, flags=flags@entry=0) at ./Zend/zend_execute_API.c:1141
#25 0x000055a86a94358d in zend_lookup_class (name=<optimized out>) at ./Zend/zend_execute_API.c:1162
#26 0x000055a86a96c645 in class_exists_impl (return_value=0x7f533f014950, skip_flags=3, flags=8, execute_data=0x7f533f014960) at ./Zend/zend_builtin_functions.c:990
#27 zif_class_exists (execute_data=0x7f533f014960, return_value=0x7f533f014950) at ./Zend/zend_builtin_functions.c:1004
#28 0x000055a86a9bbdf4 in ZEND_DO_ICALL_SPEC_RETVAL_USED_HANDLER () at ./Zend/zend_vm_execute.h:1297
#29 execute_ex (ex=0x41868fc8) at ./Zend/zend_vm_execute.h:55775
#30 0x000055a86a9c286d in zend_execute (op_array=0x7f533f070000, return_value=0x0) at ./Zend/zend_vm_execute.h:60147
#31 0x000055a86a952995 in zend_execute_scripts (type=type@entry=8, retval=retval@entry=0x0, file_count=file_count@entry=3) at ./Zend/zend.c:1799
#32 0x000055a86a8ef78a in php_execute_script (primary_file=primary_file@entry=0x7ffc1f852e30) at ./main/main.c:2541
#33 0x000055a86a793aed in main (argc=<optimized out>, argv=<optimized out>) at ./sapi/fpm/fpm/fpm_main.c:1914
PHP backtrace:
[0x7f533f014b70] Composer\Autoload\includeFile("/zoon/zoon/vendor/composer/../..//Module/Zext/Orm/ZextCommentObject.php") /zoon/zoon/vendor/composer/ClassLoader.php:571
[0x7f533f014af0] Composer\Autoload\ClassLoader->loadClass("Z\Module\Zext\Orm\ZextCommentObject") /zoon/zoon/vendor/composer/ClassLoader.php:428
[0x7f533f014aa0] (main) /zoon/zoon/Module/Comment/Orm/CommentObject.php:154
[0x7f533f014a40] Composer\Autoload\includeFile("/zoon/zoon/vendor/composer/../..//Module/Comment/Orm/CommentObject.php") /zoon/zoon/vendor/composer/ClassLoader.php:571
[0x7f533f0149c0] Composer\Autoload\ClassLoader->loadClass("Z\Module\Comment\Orm\CommentObject") /zoon/zoon/vendor/composer/ClassLoader.php:428
[0x7f533f014960] class_exists("Z\Module\Comment\Orm\CommentObject") [internal function]
[0x7f533f0148f0] Zoon\ORM\Mongo\MongoMapper->prepareObjectClassName() /zoon/zoon/vendor/zoon/orm/src/Mongo/MongoMapper.php:174
... other stuff
Here's what I get when inspecting the class entries of the 3 interfaces which CommentObject actually extends (0x43e67d60 is the CE of CommentObject aka the parent_ce of zend_try_early_bind):
(gdb) printf "%s\n", ((zend_class_entry*)0x43e67d60)->name->val
Z\Module\Comment\Orm\CommentObject
(gdb) p (((zend_class_entry*)0x43e67d60)->interfaces[0])
$72 = (zend_class_entry *) 0x41868f48
(gdb) p (((zend_class_entry*)0x43e67d60)->interfaces[1])
$73 = (zend_class_entry *) 0x41868f88
(gdb) p (((zend_class_entry*)0x43e67d60)->interfaces[2])
$74 = (zend_class_entry *) 0x41868fc8
(gdb) p (((zend_class_entry*)0x43e67d60)->interfaces[0])->type
$68 = 65 'A'
(gdb) p (((zend_class_entry*)0x43e67d60)->interfaces[1])->type
$69 = 2 '\002'
(gdb) p (((zend_class_entry*)0x43e67d60)->interfaces[2])->type
$70 = 97 'a'
(gdb) printf "%s\n", (((zend_class_entry*)0x43e67d60)->interfaces[0])->name->val
Cannot access memory at address 0xddde8fbc0245db50
(gdb) printf "%s\n", (((zend_class_entry*)0x43e67d60)->interfaces[1])->name->val
Cannot access memory at address 0xf16aa6cb353b4ff0
(gdb) printf "%s\n", (((zend_class_entry*)0x43e67d60)->interfaces[2])->name->val
Cannot access memory at address 0x8b207ca4bb626fc1
As you can see only the second interface has a valid type of ZEND_USER_CLASS, and in all cases the names are unreadable, possibly indicating that pointers contained in interfaces point to just gibberish.
Note that the autoloading of the ZextCommentObject seems to be triggered while parsing CommentObject by some internal opcache logic (maybe zend_accel_inheritance_cache_get?), not by any userland code requiring ZextCommentObject in the CommentObject class (like 154 of CommentObject from the PHP backtrace is just the line with the class declaration, which doesn't mention ZextCommentObject in any way).
PHP 8.1.13, opcache enabled, JIT disabled (due to other segfaults I'll try to report too)
Ubuntu 20.04, ondrej repos
Hello!
We'd like to use 8.0 attributes in generated arginfo files for our extensions.
it seems that #[\SensitiveParameter]
is supported, but that's about not:
namespace MyExtension {
class Foobar {
#[\MyExtension\FooAttribute]
public function getBaz() {
//
}
}
class FooAttribute { }
}
I am using phpbb 3.3.8. I have:
mariadb 10.4.26-1
php-fpm 7.4.30-1
apache 2.4.54
This is a completely new installation. I was able to connect to install the system. I can work on the ACP without any issues.
I have put in my forum structure without any issues.
Then I went to register a user and agree to the conditions. I filled out the page with my ID,etc and get:
Service Unavailable The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
This would imply something bad happened talking to the php-fpm system. Looking at the logs there, I see: 1
[18-Nov-2022 15:42:30.741346] DEBUG: pid 9175350, fpm_pctl_perform_idle_server_maintenance(), line 382: [pool www] currently 0 active children, 16 spare children, 16 running children. Spawning rate 1 [18-Nov-2022 15:42:31.429597] DEBUG: pid 9175350, fpm_event_loop(), line 430: event module triggered 2 events [18-Nov-2022 15:42:31.429702] DEBUG: pid 9175350, fpm_event_loop(), line 430: event module triggered 1 events [18-Nov-2022 15:42:31.440999] DEBUG: pid 9175350, fpm_got_signal(), line 82: received SIGCHLD [18-Nov-2022 15:42:31.441022] DEBUG: pid 9175350, fpm_event_loop(), line 430: event module triggered 1 events [18-Nov-2022 15:42:31.441110] WARNING: pid 9175350, fpm_children_bury(), line 259: [pool www] child 11207038 exited on signal 4 (SIGILL) after 256870.558712 seconds from start [18-Nov-2022 15:42:31.441184] DEBUG: pid 9175350, fpm_children_make(), line 407: blocking signals before child birth [18-Nov-2022 15:42:31.449567] DEBUG: pid 9175350, fpm_children_make(), line 431: unblocking signals, child born [18-Nov-2022 15:42:31.449689] NOTICE: pid 9175350, fpm_children_make(), line 437: [pool www] child 11207040 started [18-Nov-2022 15:42:31.741848] DEBUG: pid 9175350, fpm_pctl_perform_idle_server_maintenance(), line 382: [pool www] currently 0 active children, 16 spare children, 16 running children. Spawning rate 1 [18-Nov-2022 15:42:32.741994] DEBUG: pid 9175350, fpm_pctl_perform_idle_server_maintenance(), line 382: [pool www] currently 0 active children, 16 spare children, 16 running children. Spawning rate
In the apache log I see:
[Fri Nov 18 15:42:31.429807 2022] [proxy_fcgi:error] [pid 12648840:tid 12851] [client 9.211.126.63:54367] AH01067: Failed to read FastCGI header, referer: https://birch4.xxx.xxxxxx.xxx.com/PlayScreen/ucp.php?mode=register&sid=70daf83648343a147a3d8db77b71abb0 [Fri Nov 18 15:42:31.429855 2022] [proxy_fcgi:error] [pid 12648840:tid 12851] (70014)End of file found: [client 9.211.126.63:54367] AH01075: Error dispatching request to : , referer: https://birch4.xxx.xxxxxx.xxx.com/PlayScreen/ucp.php?mode=register&sid=70daf83648343a147a3d8db77b71abb0
Resulted in this output:
The system cannot register a user.
But I expected this output instead:
Registration completed.
Looking at the system with the kernel debugger, we can see that the stack is corrupted. Further testing shows that the stack is corrupted at:
pvthread+092C00 STACK:
[9000000000E65F4]strncpy+0000F4 ()
[90000000014E960]__res_vinit+0008A0 (??, ??)
[1003C4F10]00000001003C4F10 ()
[100099FA0]execute_ex+005300 (??)
[1000A2430]zend_execute+000170 (??, ??)
[1000DFF44]zend_execute_scripts+000078 (??, ??, ??)
[00000000]00000000 ()
That's when the strncpy starts overwriting the back frame pointer and the return address.
Note that there is also corruption further down in the stack as the bottom of the call stack is not shown.
when entering strncpy.
Unfortunately, I am not a php-fpm developer and I debug from the kernel level up. If you can tell me how to generate additional details to assist in debugging, I am happy to do so. This is creatable on demand for me.
php 7.3.40
AIX 730
In the same way that wordpress was added to the community build in: #9942, it would be good to add Drupal as well, to help catch potential incompatibilities early.
Many applications work with money, weights, dimensions. Many applications store data in DECIMAL database fields. It would be nice if this data type will be supported by the PHP core without workarounds like bcmath. It is unintuitive to use string typehints for decimal numbers instead of just "decimal". In PHP8, passing float values to bcmath may lead to issues (sic!). It is unintuitive to use functions for math operations instead of just + - / * etc. With the native decimal support, the bcmath extension can be retired.
Hi
from 3/21/2023 daylight save removed from Iran timezone and this is right when we use date funcion but on intl we have problem and not applied yet
The following code:
<?php
$formatter = new \IntlDateFormatter('en_US@calendar=persian', \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, 'Asia/Tehran', \IntlDateFormatter::TRADITIONAL, "dd/MM/yyyy h:mm a z");
echo $formatter->format(new \DateTime());
?>
Resulted in this output:
06/01/1402 4:15 PM GMT+4:30
But I expected this output instead:
06/01/1402 3:15 PM GMT+3:30
### PHP Version
8.2
### Operating System
Linux
as the title says:
Because of this uncertainty in loose comparison:
Prior to PHP 8.0.0, a string needle will match an array value of 0 in non-strict mode, and vice versa. That may lead to undesirable results. Similar edge cases exist for other types, as well. If not absolutely certain of the types of values involved, always use the strict flag to avoid unexpected behavior.
it just leads to bugs if you forgot the true.
### Description
/bin/sh /builds/php-8.2.4/libtool --silent --preserve-dup-deps --tag CC --mode=compile gcc-12 -Iext/standard/ -I/builds/php-8.2.4/ext/standard/ -I/builds/php-8.2.4/include -I/builds/php-8.2.4/main -I/builds/php-8.2.4 -I/builds/php-8.2.4/ext/date/lib -I/usr/include/libxml2 -I/usr/include/libpng16 -I/builds/php-8.2.4/ext/mbstring/libmbfl -I/builds/php-8.2.4/ext/mbstring/libmbfl/mbfl -I/builds/php-8.2.4/TSRM -I/builds/php-8.2.4/Zend -D_GNU_SOURCE -D_REENTRANT -pthread -fno-common -Wformat-truncation -Wlogical-op -Wduplicated-cond -Wno-clobbered -Wall -Wextra -Wno-strict-aliasing -Wno-unused-parameter -Wno-sign-compare -g -O2 -fvisibility=hidden -pthread -Wimplicit-fallthrough=1 -DZTS -DZEND_SIGNALS -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -c /builds/php-8.2.4/ext/standard/link.c -o ext/standard/link.lo -MMD -MF ext/standard/link.dep -MT ext/standard/link.lo
In function ‘from_zval_write_sockaddr_aux’,
inlined from ‘from_zval_write_name’ at /builds/php-8.2.4/ext/sockets/conversions.c:1041:2:
/builds/php-8.2.4/ext/sockets/conversions.c:727:9: warning: ‘family’ may be used uninitialized [-Wmaybe-uninitialized]
727 | switch (family) {
| ^~~~~~
/builds/php-8.2.4/ext/sockets/conversions.c: In function ‘from_zval_write_name’:
/builds/php-8.2.4/ext/sockets/conversions.c:703:25: note: ‘family’ was declared here
703 | int family;
| ^~~~~~
/bin/sh /builds/php-8.2.4/libtool --silent --preserve-dup-deps --tag CC --mode=compile gcc-12 -Iext/standard/ -I/builds/php-8.2.4/ext/standard/ -I/builds/php-8.2.4/include -I/builds/php-8.2.4/main -I/builds/php-8.2.4 -I/builds/php-8.2.4/ext/date/lib -I/usr/include/libxml2 -I/usr/include/libpng16 -I/builds/php-8.2.4/ext/mbstring/libmbfl -I/builds/php-8.2.4/ext/mbstring/libmbfl/mbfl -I/builds/php-8.2.4/TSRM -I/builds/php-8.2.4/Zend -D_GNU_SOURCE -D_REENTRANT -pthread -fno-common -Wformat-truncation -Wlogical-op -Wduplicated-cond -Wno-clobbered -Wall -Wextra -Wno-strict-aliasing -Wno-unused-parameter -Wno-sign-compare -g -O2 -fvisibility=hidden -pthread -Wimplicit-fallthrough=1 -DZTS -DZEND_SIGNALS -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -c /builds/php-8.2.4/ext/standard/math.c -o ext/standard/math.lo -MMD -MF ext/standard/math.dep -MT ext/standard/math.lo
/builds/php-8.2.4/ext/sockets/conversions.c: In function ‘from_zval_write_controllen’:
/builds/php-8.2.4/ext/sockets/conversions.c:1122:31: warning: ‘len’ may be used uninitialized [-Wmaybe-uninitialized]
1122 | msghdr->msg_control = accounted_emalloc(len, ctx);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/builds/php-8.2.4/ext/sockets/conversions.c:1112:18: note: ‘len’ was declared here
1112 | uint32_t len;
| ^~~
### PHP Version
PHP 8.2.4
### Operating System
SLES 15.4 with gcc 12
All file functions, incl. dir functions like file_exists()
or is_dir()
return false
when the input is empty.
One exception is realpath()
, it returns the current directory when ''
is given.
The reason is probably the way how realpath()
is written, the path is probably checked if absolute and if not, it is appended to the current directory, even if empty.
After a fix, I expect realpath('')
to return false
.
It is probably not a bug, as documented so [1], but I propose this to be fixed to be consistent with other file functions.
The following code:
<?php
function test($i, $s) {
try {
json_decode($s, false, 999999999, JSON_THROW_ON_ERROR);
echo "Test $i passed\n";
} catch (Exception $e) {
echo "Test $i FAILED: $e\n";
}
}
// String like [[[[...1...]]]] fails at length 9999, nesting depth 4999.
test(1, str_repeat('[', 4998) . '1' . str_repeat(']', 4998)); // pass
test(2, str_repeat('[', 4999) . '1' . str_repeat(']', 4999)); // FAIL
// String like [1,[1,[1,...1...]]] fails at length 10001, nesting depth 2499.
test(3, str_repeat('[1,', 2499) . '1' . str_repeat(']', 2499)); // pass
test(4, str_repeat('[1,', 2500) . '1' . str_repeat(']', 2500)); // FAIL
// Flat string like [[1],[1],[1]...] passes even at much greater length.
test(5, '[' . str_repeat('[1],', 9999) . '1]'); // pass
?>
Resulted in this output:
Test 1 passed
Test 2 FAILED: JsonException: Syntax error in json_decode_bug.php:5
Stack trace:
#0 json_decode_bug.php(5): json_decode()
#1 json_decode_bug.php(14): test()
#2 {main}
Test 3 passed
Test 4 FAILED: JsonException: Syntax error in json_decode_bug.php:5
Stack trace:
#0 json_decode_bug.php(5): json_decode()
#1 json_decode_bug.php(18): test()
#2 {main}
Test 5 passed
(I've removed the directory names from the stack trace for brevity.)
But I expected this output instead:
Test 1 passed
Test 2 passed
Test 3 passed
Test 4 passed
Test 5 passed
Note that the exception message ("Syntax error') is different from what I get when I reduce the maximum depth argument from 999999999 to 999. Then I get JsonException: Maximum stack depth exceeded
instead (which is expected).
So it looks like the parser hits an undocumented limit when the input string reaches 10,000 characters, but only for the heavily-nested input.
PHP 8.1.13
Arch Linux (x86_64)
For the past few months at least, messages I've sent to mailing lists (php-general) have been bouncing (after some time) with DNS fetch errors.
I'm experiencing no other email related issues and have checked everything I can think of in my side, but the issues persist.
The last bounce I received, on the 23rd Dec, for a message sent on 16th Dec, contained the following error message:
Hi. This is the qmail-send program at lists.php.net.
I'm afraid I wasn't able to deliver your message to the following addresses.
This is a permanent error; I've given up. Sorry it didn't work out.
<php-general@lists.php.net>:
ezmlm-send: fatal: error fetching DNS record for allenjb.me.uk: temporary failure
I'm not going to try again; this message has been in the queue too long.
All messages are sent from my domain, allenjb.me.uk, hosted on Fastmail.
I am happy to forward a full copy of a bounce message on request.
n/a
n/a
Why do expressions match
with &&
or ||
operator behave like the example? What is the reason for returning false
?
The following code: https://3v4l.org/KktKB#v8.2.4
<?php
$result = match('test') {
'test' && true => true,
'test2' && true => true,
default => false,
};
var_dump($result);
Resulted in this output:
bool(false)
But I expected this output instead:
bool(true)
8.2
No response
The following code:
<?php
$a = [];
$a = preg_replace_callback_array($a,$a,$b,$b)
?>
Resulted in this output:
Warning: Undefined variable $b in Standard input code on line 3
Deprecated: preg_replace_callback_array(): Passing null to parameter #3 ($limit) of type int is deprecated in Standard input code on line 3
Segmentation fault (core dumped)
But I expected something like this output instead (I am not sure about the null values. At the very least I would not expect a segmentation fault.):
[rocky@fuzz php-src]$ cat <<'EOF' | ~/php-src/sapi/cli/php
<?php
$a = [];
$a = preg_replace_callback_array($a,$a,null,null)
?>
EOF
Fatal error: Uncaught Error: preg_replace_callback_array(): Argument #4 ($count) cannot be passed by reference in Standard input code:3
Stack trace:
#0 {main}
thrown in Standard input code on line 3
How to compile:
./buildconf --force
./configure --disable-all --enable-debug-assertions --enable-option-checking=fatal --without-pcre-jit --disable-cgi --with-pic
make -j$(nproc)
php-8.2.4RC1
Rocky Linux release 9.1 (Blue Onyx)
I have a piece of code that tries to normalise the encoding of incoming strings using mb_detect_encoding()
. While upgrading to PHP 8.1, I've noticed that a test which ensures that an urlencoded UTF-8 sequence (party hat emoji) now fails. It all comes down to a behaviour change of mb_detect_encoding()
when passing UTF-8
and ISO-8859-1
(in which ever order) as $encodings
in PHP 8.1.
I know that the way this method works (or the way that determining the enconding of a string works at all) can not be 100% realiable, so I'd also agree on not classifying this as a bug. However, it is an undocumented behaviour change introduced in 8.1 that might break existing code as it did with mine.
I assume that this change has been introduced with 28b346b.
<?php
echo mb_detect_encoding('🥳', ['UTF-8', 'ISO-8859-1']);
Resulted in this output:
ISO-8859-1
But I expected this output instead:
UTF-8
8.1.1
No response
Before enum exist, i used constant to define the array key. Now i want to use enum. But i got error when i declare the enum as array key. so i do the workaround like this:
if (!function_exists('_api')) {
/**
* use enum as Array Key.
*
* @param array $values
* @param \App\Enums\Api\ResponseKey $key
* @param mixed $data
* @return array
*/
function _api(?array &$values, ResponseKey $key, $data)
{
if (! is_array($values)) $values = [];
$values[$key->value] = $data;
return $values;
}
}
Then call it like _api($data, ResponseKey::message, "success");
Can this workaround can be implemented as feature for future PHP?
When assigning to a variable &
must used to assign the value by reference.
Currently when a function returning a reference is called, it seems the optimizer is not smart enough to detect the result will be used by value, and the reference is always created, which make the call slower.
My usecase is heavily used public function &__get(string $name) {}
method which needs to be declared with &
for rare purposes, but normally, the result is assigned/used by value and I belive this can be optimized by php engine to make the performance the same as if the method would be declared /wo &
.
I know there were https://wiki.php.net/rfc/explicit_send_by_ref. This feature request is solely to improve the performance /wo any language change.
/bin/sh /builds/php-8.2.4/libtool --silent --preserve-dup-deps --tag CC --mode=compile gcc-12 -IZend/ -I/builds/php-8.2.4/Zend/ -I/builds/php-8.2.4/include -I/builds/php-8.2.4/main -I/builds/php-8.2.4 -I/builds/php-8.2.4/ext/date/lib -I/usr/include/libxml2 -I/usr/include/libpng16 -I/builds/php-8.2.4/ext/mbstring/libmbfl -I/builds/php-8.2.4/ext/mbstring/libmbfl/mbfl -I/builds/php-8.2.4/TSRM -I/builds/php-8.2.4/Zend -D_GNU_SOURCE -D_REENTRANT -pthread -fno-common -Wformat-truncation -Wlogical-op -Wduplicated-cond -Wno-clobbered -Wall -Wextra -Wno-strict-aliasing -Wno-unused-parameter -Wno-sign-compare -g -O2 -fvisibility=hidden -pthread -Wimplicit-fallthrough=1 -DZTS -DZEND_SIGNALS -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -c /builds/php-8.2.4/Zend/Optimizer/zend_cfg.c -o Zend/Optimizer/zend_cfg.lo -MMD -MF Zend/Optimizer/zend_cfg.dep -MT Zend/Optimizer/zend_cfg.lo
/builds/php-8.2.4/Zend/zend.c: In function ‘function_copy_ctor’:
/builds/php-8.2.4/Zend/zend.c:665:21: warning: array subscript ‘zend_function {aka union _zend_function}[0]’ is partly outside array bounds of ‘unsigned char[136]’ [-Warray-bounds]
665 | func->common.arg_info = new_arg_info + 1;
| ^~
In file included from /builds/php-8.2.4/Zend/zend.h:30,
from /builds/php-8.2.4/Zend/zend.c:20:
/builds/php-8.2.4/Zend/zend_alloc.h:188:69: note: object of size 136 allocated by ‘__zend_malloc’
188 | #define pemalloc(size, persistent) ((persistent)?__zend_malloc(size):emalloc(size))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
/builds/php-8.2.4/Zend/zend.c:632:16: note: in expansion of macro ‘pemalloc’
632 | func = pemalloc(sizeof(zend_internal_function), 1);
| ^~~~~~~~
/builds/php-8.2.4/Zend/zend.c:670:21: warning: array subscript ‘zend_function {aka union _zend_function}[0]’ is partly outside array bounds of ‘unsigned char[136]’ [-Warray-bounds]
670 | func->common.attributes = NULL;
| ^~
/builds/php-8.2.4/Zend/zend_alloc.h:188:69: note: object of size 136 allocated by ‘__zend_malloc’
188 | #define pemalloc(size, persistent) ((persistent)?__zend_malloc(size):emalloc(size))
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
/builds/php-8.2.4/Zend/zend.c:632:16: note: in expansion of macro ‘pemalloc’
632 | func = pemalloc(sizeof(zend_internal_function), 1);
| ^~~~~~~~
PHP 8.2.4
SLES 15.4 gcc 12
### Description
/bin/sh /builds/php-8.2.4/libtool --silent --preserve-dup-deps --tag CC --mode=compile gcc-12 -Isapi/phpdbg/ -I/builds/php-8.2.4/sapi/phpdbg/ -I/builds/php-8.2.4/include -I/builds/php-8.2.4/main -I/builds/php-8.2.4 -I/builds/php-8.2.4/ext/date/lib -I/usr/include/libxml2
-I/usr/include/libpng16 -I/builds/php-8.2.4/ext/mbstring/libmbfl -I/builds/php-8.2.4/ext/mbstring/libmbfl/mbfl -I/builds/php-8.2.4/TSRM -I/builds/php-8.2.4/Zend -D_GNU_SOURCE -D_REENTRANT -pthread -fno-common -Wformat-truncation -Wlogical-op -Wduplicated-cond -Wno-clobbered -Wall -Wextra -Wno-strict-aliasing -Wno-unused-parameter -Wno-sign-compare -g -O2 -fvisibility=hidden -pthread -Wimplicit-fallthrough=1 -DZTS -DZEND_SIGNALS -D_GNU_SOURCE -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -c /builds/php-8.2.4/sapi/phpdbg/phpdbg_out.c -o sapi/phpdbg/phpdbg_out.lo -MMD -MF sapi/phpdbg/phpdbg_out.dep -MT sapi/phpdbg/phpdbg_out.lo
/builds/php-8.2.4/Zend/zend_API.c: In function ‘zend_register_functions’:
/builds/php-8.2.4/Zend/zend_API.c:2821:49: warning: array subscript ‘zend_function {aka union _zend_function}[0]’ is partly outside array bounds of ‘unsigned char[136]’ [-Warray-bounds]
2821 | uint32_t num_args = reg_function->common.num_args;
| ^~
/builds/php-8.2.4/Zend/zend_API.c:2811:32: note: object of size 136 allocated by ‘malloc’
2811 | reg_function = malloc(sizeof(zend_internal_function));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/builds/php-8.2.4/Zend/zend_API.c:2822:33: warning: array subscript ‘zend_function {aka union _zend_function}[0]’ is partly outside array bounds of ‘unsigned char[136]’ [-Warray-bounds]
2822 | if (reg_function->common.fn_flags & ZEND_ACC_VARIADIC) {
| ^~
/builds/php-8.2.4/Zend/zend_API.c:2811:32: note: object of size 136 allocated by ‘malloc’
2811 | reg_function = malloc(sizeof(zend_internal_function));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/builds/php-8.2.4/Zend/zend_API.c:2827:33: warning: array subscript ‘zend_function {aka union _zend_function}[0]’ is partly outside array bounds of ‘unsigned char[136]’ [-Warray-bounds]
2827 | if (reg_function->common.arg_info && num_args) {
| ^~
/builds/php-8.2.4/Zend/zend_API.c:2811:32: note: object of size 136 allocated by ‘malloc’
2811 | reg_function = malloc(sizeof(zend_internal_function));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/builds/php-8.2.4/Zend/zend_API.c:2833:49: warning: array subscript ‘zend_function {aka union _zend_function}[0]’ is partly outside array bounds of ‘unsigned char[136]’ [-Warray-bounds]
2833 | reg_function->common.fn_flags |= ZEND_ACC_HAS_TYPE_HINTS;
| ^~
/builds/php-8.2.4/Zend/zend_API.c:2811:32: note: object of size 136 allocated by ‘malloc’
2811 | reg_function = malloc(sizeof(zend_internal_function));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/builds/php-8.2.4/Zend/zend_API.c:2833:49: warning: array subscript ‘zend_function {aka union _zend_function}[0]’ is partly outside array bounds of ‘unsigned char[136]’ [-Warray-bounds]
2833 | reg_function->common.fn_flags |= ZEND_ACC_HAS_TYPE_HINTS;
| ^~
/builds/php-8.2.4/Zend/zend_API.c:2811:32: note: object of size 136 allocated by ‘malloc’
2811 | reg_function = malloc(sizeof(zend_internal_function));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/builds/php-8.2.4/Zend/zend_API.c:2849:34: warning: array subscript ‘zend_function {aka union _zend_function}[0]’ is partly outside array bounds of ‘unsigned char[136]’ [-Warray-bounds]
2849 | (reg_function->common.fn_flags & (ZEND_ACC_HAS_RETURN_TYPE|ZEND_ACC_HAS_TYPE_HINTS))) {
| ^~
/builds/php-8.2.4/Zend/zend_API.c:2811:32: note: object of size 136 allocated by ‘malloc’
2811 | reg_function = malloc(sizeof(zend_internal_function));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/builds/php-8.2.4/Zend/zend_API.c:2859:37: warning: array subscript ‘zend_function {aka union _zend_function}[0]’ is partly outside array bounds of ‘unsigned char[136]’ [-Warray-bounds]
2859 | reg_function->common.arg_info = new_arg_info + 1;
| ^~
/builds/php-8.2.4/Zend/zend_API.c:2811:32: note: object of size 136 allocated by ‘malloc’
2811 | reg_function = malloc(sizeof(zend_internal_function));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### PHP Version
PHP 8.2.4
### Operating System
SLES 15.4 gcc 12
### Description
/bin/sh /builds/php-8.2.4/libtool --silent --preserve-dup-deps --tag CC --mode=compile gcc-12 -Iext/opcache/ -I/builds/php-8.2.4/ext/opcache/ -I/builds/php-8.2.4/include -I/builds/php-8.2.4/main -I/builds/php-8.2.4 -I/builds/php-8.2.4/ext/date/lib -I/usr/include/libxml2
-I/usr/include/libpng16 -I/builds/php-8.2.4/ext/mbstring/libmbfl -I/builds/php-8.2.4/ext/mbstring/libmbfl/mbfl -I/builds/php-8.2.4/TSRM -I/builds/php-8.2.4/Zend -D_GNU_SOURCE -D_REENTRANT -pthread -fno-common -Wformat-truncation -Wlogical-op -Wduplicated-cond -Wno-clobbered -Wall -Wextra -Wno-strict-aliasing -Wno-unused-parameter -Wno-sign-compare -g -O2 -fvisibility=hidden -pthread -Wimplicit-fallthrough=1 -DZTS -DZEND_SIGNALS -Wno-implicit-fallthrough -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -DZEND_COMPILE_DL_EXT=1 -c /builds/php-8.2.4/ext/opcache/jit/zend_jit.c -o ext/opcache/jit/zend_jit.lo -MMD -MF ext/opcache/jit/zend_jit.dep -MT ext/opcache/jit/zend_jit.lo
In file included from /builds/php-8.2.4/ext/opcache/jit/zend_jit.c:710:
In function ‘dasm_setupglobal’,
inlined from ‘zend_jit_trace_allocate_exit_group’ at ext/opcache/jit/zend_jit_trace.c:95:2,
inlined from ‘zend_jit_trace_allocate_exit_point’ at ext/opcache/jit/zend_jit_trace.c:125:11:
/builds/php-8.2.4/ext/opcache/jit/dynasm/dasm_x86.h:127:19: warning: array subscript -10 is outside array bounds of ‘void *[38]’ [-Warray-bounds]
127 | D->globals = gl - 10; /* Negative bias to compensate for locals. */
| ~~~^~~~
In file included from /builds/php-8.2.4/ext/opcache/jit/zend_jit.c:768:
/builds/php-8.2.4/ext/opcache/jit/zend_jit_x86.dasc: In function ‘zend_jit_trace_allocate_exit_point’:
/builds/php-8.2.4/ext/opcache/jit/zend_jit_x86.dasc:143:14: note: at offset -80 into object ‘dasm_labels’ of size 304
143 | static void* dasm_labels[zend_lb_MAX];
| ^~~~~~~~~~~
In function ‘dasm_setupglobal’,
inlined from ‘zend_jit’ at /builds/php-8.2.4/ext/opcache/jit/zend_jit.c:2729:2:
/builds/php-8.2.4/ext/opcache/jit/dynasm/dasm_x86.h:127:19: warning: array subscript -10 is outside array bounds of ‘void *[38]’ [-Warray-bounds]
127 | D->globals = gl - 10; /* Negative bias to compensate for locals. */
| ~~~^~~~
/builds/php-8.2.4/ext/opcache/jit/zend_jit_x86.dasc: In function ‘zend_jit’:
/builds/php-8.2.4/ext/opcache/jit/zend_jit_x86.dasc:143:14: note: at offset -80 into object ‘dasm_labels’ of size 304
143 | static void* dasm_labels[zend_lb_MAX];
| ^~~~~~~~~~~
In function ‘dasm_setupglobal’,
inlined from ‘zend_jit_trace’ at ext/opcache/jit/zend_jit_trace.c:4054:2:
/builds/php-8.2.4/ext/opcache/jit/dynasm/dasm_x86.h:127:19: warning: array subscript -10 is outside array bounds of ‘void *[38]’ [-Warray-bounds]
127 | D->globals = gl - 10; /* Negative bias to compensate for locals. */
| ~~~^~~~
/builds/php-8.2.4/ext/opcache/jit/zend_jit_x86.dasc: In function ‘zend_jit_trace’:
/builds/php-8.2.4/ext/opcache/jit/zend_jit_x86.dasc:143:14: note: at offset -80 into object ‘dasm_labels’ of size 304
143 | static void* dasm_labels[zend_lb_MAX];
| ^~~~~~~~~~~
In file included from /builds/php-8.2.4/ext/opcache/jit/zend_jit.c:4428:
ext/opcache/jit/zend_jit_trace.c:6472:86: warning: ‘gen_handler’ may be used uninitialized [-Wmaybe-uninitialized]
6472 | (gen_handler || !ra || !ra[ssa_op->op1_def]));
| ^~
ext/opcache/jit/zend_jit_trace.c:4298:30: note: ‘gen_handler’ was declared here
4298 | bool gen_handler;
| ^~~~~~~~~~~
In function ‘dasm_setupglobal’,
inlined from ‘zend_jit_trace_exit_to_vm’ at ext/opcache/jit/zend_jit_trace.c:7001:2,
inlined from ‘zend_jit_blacklist_trace_exit’ at ext/opcache/jit/zend_jit_trace.c:7721:14:
/builds/php-8.2.4/ext/opcache/jit/dynasm/dasm_x86.h:127:19: warning: array subscript -10 is outside array bounds of ‘void *[38]’ [-Warray-bounds]
127 | D->globals = gl - 10; /* Negative bias to compensate for locals. */
| ~~~^~~~
/builds/php-8.2.4/ext/opcache/jit/zend_jit_x86.dasc: In function ‘zend_jit_blacklist_trace_exit’:
/builds/php-8.2.4/ext/opcache/jit/zend_jit_x86.dasc:143:14: note: at offset -80 into object ‘dasm_labels’ of size 304
143 | static void* dasm_labels[zend_lb_MAX];
| ^~~~~~~~~~~
In function ‘dasm_setupglobal’,
inlined from ‘zend_jit_make_stubs’ at /builds/php-8.2.4/ext/opcache/jit/zend_jit.c:4712:2,
inlined from ‘zend_jit_startup’ at /builds/php-8.2.4/ext/opcache/jit/zend_jit.c:5001:9:
/builds/php-8.2.4/ext/opcache/jit/dynasm/dasm_x86.h:127:19: warning: array subscript -10 is outside array bounds of ‘void *[38]’ [-Warray-bounds]
127 | D->globals = gl - 10; /* Negative bias to compensate for locals. */
| ~~~^~~~
/builds/php-8.2.4/ext/opcache/jit/zend_jit_x86.dasc: In function ‘zend_jit_startup’:
/builds/php-8.2.4/ext/opcache/jit/zend_jit_x86.dasc:143:14: note: at offset -80 into object ‘dasm_labels’ of size 304
143 | static void* dasm_labels[zend_lb_MAX];
| ^~~~~~~~~~~
### PHP Version
PHP 8.2.4
### Operating System
SLES 15.4 gcc 12