php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80535 Backward compatibility issue - FATAL error
Submitted: 2020-12-20 16:01 UTC Modified: 2021-01-03 01:34 UTC
From: legrand101 at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 8.0.0 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: legrand101 at gmail dot com
New email:
PHP Version: OS:

 

 [2020-12-20 16:01 UTC] legrand101 at gmail dot com
Description:
------------
After upgrading to PHP 8, I start getting FATAL error for simple statement that use to work on PHP 7. This statement is now producing a FATAL error (PHP Fatal error:  Uncaught Error: Attempt to modify property  on null) on PHP 8:
$T = &$r->country->state->city;

Before PHP8 both $r and properties (r->country, r->country->state, r->country->state->city) are implicitly instantiated as standard classs and $T is pointer.




Test script:
---------------
$T = &$r->country->state->city;
$T = 'home';

Expected result:
----------------
no fatal error. $r object implicitly created. $T and $r->country->state->city value are 'home'.

var_dump($r);
object(stdClass)#34 (1) {
  ["country"]=>
  object(stdClass)#36 (1) {
    ["state"]=>
    object(stdClass)#37 (1) {
      ["city"]=>
      &string(4) "home"
    }
  }
}


var_dump($T);
string(4) "home"


Actual result:
--------------
PHP Fatal error:  Uncaught Error: Attempt to modify property  on null

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-12-20 16:11 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Package: Reproducible crash +Package: Scripting Engine problem -Assigned To: +Assigned To: cmb
 [2020-12-20 16:11 UTC] cmb@php.net
That code already issued E_WARNING as of PHP 7.4.0[1], and the
warning was promoted to an Error exception according to the
respective RFC[2].  It is also documented as backward incompatible
change in the migration guide[3].

Note that an Error exception is not a fatal error per se, and that
even a fatal error is not a crash.

[1] <https://3v4l.org/h3NJj>
[2] <https://wiki.php.net/rfc/engine_warnings>
[3] <https://www.php.net/manual/en/migration80.incompatible.php>
 [2020-12-20 20:39 UTC] legrand101 at gmail dot com
Thanks for the quick response. I was upgrading from PHP7.0 so didn't get any warnings. By crash, I meant the my script was crashing.

So, is there any work around other than explicitly instantiating each variable. This seems like a big inconvenience, special if one relied this behavior for API development.
 [2020-12-20 23:14 UTC] cmb@php.net
> So, is there any work around other than explicitly instantiating
> each variable.

I don't think so.  If you strongly feel that this "feature" should
not have been disallowed, please raise that on the internals
mailing list, although I consider it unlikely that the change will
be reverted.

> there is a reason to introduce warnings years before

In this case it has been only *one* year.
 [2020-12-21 00:35 UTC] legrand101 at gmail dot com
This is project personal I started more three years ago, so it's no big deal for me. I just revert back to PHP7. I only wanted to checkout the performance improvements.

Even though, it's unlike to be reverted, I would like to add this issue to the internals mailing list. I don't see why making more things more restrictive is an improvement. How do I bring it up to the internals mailing list?
 [2020-12-21 09:27 UTC] nikic@php.net
Worth noting that this warning is actually very old (dating back all the way to PHP 5.0: https://3v4l.org/nkocf). PHP 7.4 fixed a special case where the warning was missing (references as opposed to direct writes) and PHP 8.0 removed this functionality completely.

Note that auto-vivification is still supported for arrays (and I don't believe there are plans to remove it there).
 [2021-01-03 01:19 UTC] legrand101 at gmail dot com
Hi nikic,

https://3v4l.org/nkocf is different example than what is have. Using a pointer will work(there's no warning for that until 7.4.0). See https://3v4l.org/H5SPf.
 [2021-01-03 01:34 UTC] legrand101 at gmail dot com
https://3v4l.org/H5SPf
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon May 05 03:01:31 2025 UTC