php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64731 Constructor called from trait gives warning message
Submitted: 2013-04-28 22:42 UTC Modified: 2013-05-01 12:18 UTC
From: Danack at basereality dot com Assigned:
Status: Closed Package: Compile Failure
PHP Version: 5.5.0beta4 OS: Ubuntu 12.04 LTS
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: Danack at basereality dot com
New email:
PHP Version: OS:

 

 [2013-04-28 22:42 UTC] Danack at basereality dot com
Description:
------------
Calling a constructor that takes a parameter inside a trait, the parameter isn't 
passed to the constructor and so a warning is generated and the constructor is 
missing a parameter.

I was only able to get this to be repeatable when the trait is defined in a file 
that is outside of the current directory i.e. the bug is dependent of file 
location, so may be hard to replicate.

This was seen both against 5.5.0beta4 and the current 5.5 git head.

This issue isn't present on 5.4 (afaik).

Test script:
---------------
Code is a bit too long to post entirely, example files are here:

https://gist.github.com/Danack/5478333

with instructions of where to put the files to see the bug.


The relevant parts of the code are:

trait Singleton{

   public static function getInstance($data = array()){ 
      new static($data);
   }
}

class TestClass {

    use Singleton;
    public function __construct($params){
		echo "params count is ".count($params)."<br/>";
	}

}

$params = array(
	'test' => 'value'
);


TestClass::getInstance($params);


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

params count is 1
Ok





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

Warning: Missing argument 1 for TestClass::__construct(), called in 
/home/intahwebz/12345/vendor/intahwebz/utils/src/Intahwebz/Utils/Singleton.php on 
line 15 and defined in /home/intahwebz/12345/basereality/traitTestBroken.php on 
line 12
params count is 0
Ok

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-04-28 22:49 UTC] Danack at basereality dot com
Forgot to post my configure settings.

 configure  \
                      --disable-debug \
                      --disable-rpath \
                      --enable-fpm \
                      --enable-inline-optimization \
                      --enable-json \
                      --enable-mbregex \
                      --enable-mbstring \
                      --enable-pcntl \
                      --enable-sockets \
                      --enable-sysvsem \
                      --enable-sysvshm \
                      --enable-zip \
                      --with-bz2 \
                      --with-config-file-path=/etc \
                      --with-curl \
                      --with-freetype-dir=/usr/lib \
                      --with-gd \
                      --with-jpeg-dir=/usr/lib \
                      --with-mcrypt \
                      --with-pecl=/usr/lib \
                      --with-pic \
                      --with-png-dir=/usr/lib \
                      --with-zlib \
                      --with-mhash \
                      --with-mysql \
                      --with-mysqli \
                      --with-pcre-regex \
                      --without-pdo-sqlite
 [2013-04-29 16:07 UTC] laruence@php.net
I can not produce this: http://3v4l.org/KYfgY
 [2013-04-29 16:07 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2013-05-01 12:18 UTC] Danack at basereality dot com
Apologies, this was due to an out-of-date composer lock file i.e. my fault.
 [2013-05-01 12:18 UTC] Danack at basereality dot com
-Status: Feedback +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC