Bug #81652 [Com]: The value of error_reporting() gets overridden

From: Date: Tue, 23 Nov 2021 21:49:25 +0000
Subject: Bug #81652 [Com]: The value of error_reporting() gets overridden
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237953@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81652&edit=1

 ID:                 81652
 Comment by:         antonino dot spampinato86 at gmail dot com
 Reported by:        joupicky at gmail dot com
 Summary:            The value of error_reporting() gets overridden
 Status:             Open
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   Ubuntu 20.04.3 LTS
 PHP Version:        8.0.13
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2021-11-23 13:20:23] cmb@php.net

I cannot reproduce this with PHP 8.0.13 with Apache 2.4 (mod_php)
on Windows.

------------------------------------------------------------------------
[2021-11-23 11:45:31] joupicky at gmail dot com

Description:
------------
The value of error_reporting() function (and global error reporting setting) gets overridden when a
native PHP function such as random_int() or filemtime() gets called with a suppress "@"
operator and assigned to a class variable.

I am running PHP Version 8.0.13 with the latest Apache2. I was able to reproduce this also when ran
as FPM. I was not able to reproduce this when called as CLI. I am using a precompiled binaries from
https://launchpad.net/~ondrej/+archive/ubuntu/php/.
I was not able to reproduce this on PHP7.4 when install via Ubuntu repos. This might be only
relevant to the build from that repository (which is used by many people AFAIK).

Test script:
---------------
<?php

error_reporting(E_ALL);

class Foo
{
    public $a;

    public function bar() {
        $this->a = (true) ? @random_int(0, 100) : false;
    }
}

var_dump(error_reporting()); //int(32767) = E_ALL
$c = new Foo();

$c->bar();

var_dump(error_reporting()); //random int

Expected result:
----------------
int(32767)
int(32767) 

Actual result:
--------------
int(32767)
int(5) //random int


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=81652&edit=1


Thread (10 messages)

« previous php.bugs (#237953) next »