Bug #81652 [Opn->Ver]: The value of error_reporting() gets overridden
Edit report at https://bugs.php.net/bug.php?id=81652&edit=1
ID: 81652
Updated by: nikic@php.net
Reported by: joupicky at gmail dot com
Summary: The value of error_reporting() gets overridden
-Status: Open
+Status: Verified
Type: Bug
-Package: Unknown/Other Function
+Package: opcache
Operating System: Ubuntu 20.04.3 LTS
PHP Version: 8.0.13
Block user comment: N
Private report: N
New Comment:
I can repro with opcache.
Previous Comments:
------------------------------------------------------------------------
[2021-11-24 11:34:44] cmb@php.net
Do you have OPcache enabled? Maybe even JIT? Is it reproducible
without OPcache?
------------------------------------------------------------------------
[2021-11-24 00:03:04] james at gogo dot co dot nz
Final note, I can also reproduce in PHP 8.1 (adjust reproduction script as appropriate).
------------------------------------------------------------------------
[2021-11-23 23:58:42] james at gogo dot co dot nz
I'll add also that the test case can be simplified to
----------
<?php
error_reporting(E_ALL);
echo "Should Equal 32767: " . error_reporting() . "\n";
$a = true;
$b = $a ? @random_int(0,100) : false;
echo "Should Equal 32767: " . error_reporting() . "\n";
----------
It seems to the ternary which is the critical factor in producing the error.
------------------------------------------------------------------------
[2021-11-23 23:47:24] james at gogo dot co dot nz
I was able to reproduce this in a fresh Ubuntu 20.04 setup, here are reproduction steps which should
work starting from spinning up fresh Ubuntu 20.04 on Amazon EC2.
Interesting, the issue doesn't always happen if you hit the file immediately after creating it,
even if you hit it multiple times immediately after creating it, a small delay is necessary.
Test Process
--------------------
sudo su
add-apt-repository ppa:ondrej/php
apt-get update
apt-get upgrade
apt-get install php8.0-fpm apache2
a2enmod proxy_fcgi
rm /etc/apache2/sites-enabled/000-default.conf
cat /etc/apache2/sites-available/000-default.conf | grep -v "</VirtualHost>" >
/etc/apache2/sites-enabled/000-default.conf
cat >>/etc/apache2/sites-enabled/000-default.conf <<'EOF'
<FilesMatch "\.php$">
<If "-f %{REQUEST_FILENAME}">
SetHandler "proxy:unix:/var/run/php/php8.0-fpm.sock|fcgi://localhost/"
</If>
</FilesMatch>
</VirtualHost>
EOF
service apache2 restart
cat >/var/www/html/test-1.php <<'EOF'
<?php
error_reporting(E_ALL);
class Foo
{
public $a;
public function bar() {
$this->a = (true) ? @random_int(0, 100) : false;
}
}
echo "Should Equal 32767: " . error_reporting() . "\n";
$c = new Foo();
$c->bar();
echo "Should Equal 32767: " . error_reporting() . "\n";
EOF
echo "Sleeping 2 seconds to more reliably trigger the issue..."
sleep 2
for x in 1 2 3 4 ; do curl http://localhost/test-1.php;
done
----------
------------------------------------------------------------------------
[2021-11-23 21:49:25] antonino dot spampinato86 at gmail dot com
I doubt this is a valid expression for your ternary operator, also with this code the integer value
change for error_reporting occurs?
error_reporting(E_ALL);
class Foo
{
public $a;
public function seta($a) {
$b = @random_int(16, 16);
if(is_int($b))
$this->a = $b;
return $a;
}
public function numbera() {
return $this->a;
}
}
$c = new Foo();
$c->seta(0);
$var = $c->numbera();
if($var != 16)
echo 'bug' . PHP_EOL;
else
echo 'normal' . PHP_EOL;
var_dump($var, error_reporting(), @error_reporting());
The @ operator will no longer silence fatal errors (E_ERROR == 1, E_CORE_ERROR == 4, E_COMPILE_ERROR
== 64, E_USER_ERROR == 256, E_RECOVERABLE_ERROR == 4096, E_PARSE == 4)
https://www.php.net/manual/en/migration80.incompatible.php
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=81652
--
Edit this bug report at https://bugs.php.net/bug.php?id=81652&edit=1
Thread (10 messages)