php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68597 Wrong Strict report when overriding a Trait property
Submitted: 2014-12-12 17:43 UTC Modified: 2014-12-12 17:47 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: pedronaroga at gmail dot com Assigned:
Status: Open Package: Class/Object related
PHP Version: 5.5.19 OS: Windows
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-12-12 17:43 UTC] pedronaroga at gmail dot com
Description:
------------
Just recently I came up with the following E_STRICT report:

Strict standards: Declaration of Portal_IndexController::getUsuarioLogado() should be compatible with Sicneo\Controller\Action::getUsuarioLogado($fields = NULL).

I got very confused when I checked my code and saw that Sicneo\Controller\Action did not have a 'getUsuarioLogado' function. After a couple of minutes, I found out that Portal_IndexController was using a trait that had already defined a 'getUsuarioLogado' function, with the default `null` value to a `$fields` parameter.

The strict message should point to the trait instead of pointing out to the parent class.

Test script:
---------------
trait MyTrait {

    public function myFunction($test = null) {}

}

class MyParentClass {

}

class MyChildClass extends MyParentClass {

    use MyTrait;

    public function myFunction() { }

}

$obj = new MyChildClass;
$obj->myFunction();

Actual result:
--------------
Strict standards: Declaration of MyChildClass::myFunction() should be compatible with MyParentClass::myFunction($test = NULL) in [...]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-12-12 17:47 UTC] pedronaroga at gmail dot com
Uhh, I'm sorry, the `use MyTrait;` should be in MyParentClass.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Feb 17 01:01:25 2019 UTC