php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67979 overridding property on an inherited trait
Submitted: 2014-09-08 13:04 UTC Modified: 2014-09-08 19:30 UTC
From: bradley dot lee80 at googlemai dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.5.16 OS: MacOSx
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: bradley dot lee80 at googlemai dot com
New email:
PHP Version: OS:

 

 [2014-09-08 13:04 UTC] bradley dot lee80 at googlemai dot com
Description:
------------
Re-declaring properties in inherited traits throws a Fatal error

For this scenario I can get around it by having a method return a hard coded value instead of the property, but it will have to be re-declared in each version of the API.

---
From manual page: http://www.php.net/language.oop5.traits
---


Test script:
---------------
<?php
trait V1Trait
{
    protected $api_version = '1.0';
    public function getApiVersion() {
        return $this->api_version;
    }
}

trait V2Trait
{
    use V1Trait;
    protected $api_version = '2.0';
}

Expected result:
----------------
<void>

Actual result:
--------------
Fatal error: V2Trait and V1Trait define the same property ($api_version) in the composition of V2Trait. However, the definition differs and is considered incompatible. Class was composed in Traits.php on line 15

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-09-08 14:09 UTC] gron@php.net
This is intended behavior, because the value for @api_version differs.

Traits generally require explicit conflict resolution, but properties do not support conflict resolution because of their dynamic nature. So, at the moment, you get a very conservative fatal error for everything that smells like a problematic composition.
 [2014-09-08 19:30 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2014-09-08 19:30 UTC] aharvey@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 23:00:02 2026 UTC