php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75607 b/c break in traits causes fatal error
Submitted: 2017-11-30 21:41 UTC Modified: 2017-12-01 21:31 UTC
From: stuart at stuartherbert dot com Assigned: pmmaga (profile)
Status: Closed Package: Class/Object related
PHP Version: 7.2.0 OS: Ubuntu 17.10
Private report: No CVE-ID: None
 [2017-11-30 21:41 UTC] stuart at stuartherbert dot com
Description:
------------
In 7.2.0, using two traits that define the same static property cause a fatal error. Only static properties are affected. 

I've put this up on https://3v4l.org/oi4ns to show the behaviour on different PHP versions.

I couldn't find this documented in the PHP 7.2.0 release notes / migration guide.


Test script:
---------------
https://3v4l.org/oi4ns

<?php

trait T1
{
	public static $prop1 = 1;
}

trait T2
{
	public static $prop1 = 1;
}

class Base
{
	use T1;
}

class Child extends base
{
	use T2;
}


Expected result:
----------------
Expected behaviour:

- no fatal errors, no warnings, code executes


Actual result:
--------------
Actual behaviour:

- fatal error: Fatal error: Base and T2 define the same property ($prop1) in the composition of Child. However, the definition differs and is considered incompatible. Class was composed in /in/oi4ns on line 18


Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-01 21:31 UTC] pmmaga@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: pmmaga
 [2017-12-01 21:31 UTC] pmmaga@php.net
I've added a PR with a fix for the issue.
 [2017-12-16 16:11 UTC] nikic@php.net
Automatic comment on behalf of mail@pmmaga.net
Revision: http://git.php.net/?p=php-src.git;a=commit;h=83964e0468e7f4ae39cd1435f3b53f62e174ac21
Log: Fix #75607 - Check if existing static trait property is a ref before comparing
 [2017-12-16 16:11 UTC] nikic@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 12:01:30 2024 UTC