php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43167 ReflectionMethod::isConstructor() does not work for interfaces
Submitted: 2007-11-01 07:52 UTC Modified: 2008-11-02 13:08 UTC
From: sebastian@php.net Assigned: johannes (profile)
Status: Not a bug Package: Reflection related
PHP Version: 5.2.* OS: *
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: sebastian@php.net
New email:
PHP Version: OS:

 

 [2007-11-01 07:52 UTC] sebastian@php.net
Description:
------------
ReflectionMethod::isConstructor() does not work for methods that are named __construct() in interfaces.

Reproduce code:
---------------
<?php
interface Foo
{
    public function __construct(Bar $bar);
}

$interface   = new ReflectionClass('Foo');
$constructor = $interface->getMethod('__construct');
var_dump($constructor->isConstructor());

Expected result:
----------------
bool(true)

Actual result:
--------------
bool(false)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-06 13:25 UTC] helly@php.net
This is discussable as it is not really a constructor here. It simply forces the protocol for the constructor. We do mark abstract constructors as ctors though, so we imho should do so in interfaces as well.
[marcus@zaphod PHP_5_3]$ php -r 'abstract class t{abstract function __construct();} ReflectionClass::export("T");'
make: `sapi/cli/php' is up to date.
Class [ <user> abstract class t ] {
  @@ Command line code 1-1

  - Constants [0] {
  }

  - Static properties [0] {
  }

  - Static methods [0] {
  }

  - Properties [0] {
  }

  - Methods [1] {
    Method [ <user, ctor> abstract public method __construct ] {
      @@ Command line code 1 - 1
    }
  }
}
 [2008-01-07 11:46 UTC] dsp@php.net
In my opinion thats not a bug. An interface has no constructor as it cannot be initialized. As helly said, it simple forces the protocol for the constructor.
 [2008-11-02 13:08 UTC] jani@php.net
There's no bug to fix here.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC