php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53900 Reflection API shows wrong class name for namespaced type hints
Submitted: 2011-02-01 11:04 UTC Modified: 2011-02-01 13:24 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: sebastian@php.net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: trunk-SVN-2011-02-01 (SVN) OS: Irrelevant
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: sebastian@php.net
New email:
PHP Version: OS:

 

 [2011-02-01 11:04 UTC] sebastian@php.net
Description:
------------
When using namespaced classes as a type hint like in the test script attached to this bug report, the ReflectionParameter object generated for the parameter contains a fully-qualified class name for the type hinted class where the name of the namespace is duplicated (see actual output).

This also causes ReflectionParameter::getClass() to fail as no ReflectionClass object can be created for the invalid class name.

Test script:
---------------
<?php
namespace ImageTransform;

interface FileAccessAdapter
{
  public function create(ImageTransform\Image $image, $width, $height);
}

$method = new \ReflectionMethod('ImageTransform\FileAccessAdapter', 'create');

foreach ($method->getParameters() as $parameter) {
    print $parameter;
}
?>

Expected result:
----------------
Parameter #0 [ <required> ImageTransform\Image $image ]Parameter #1 [ <required> $width ]Parameter #2 [ <required> $height ]

Actual result:
--------------
Parameter #0 [ <required> ImageTransform\ImageTransform\Image $image ]Parameter #1 [ <required> $width ]Parameter #2 [ <required> $height ]

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-01 13:24 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2011-02-01 13:24 UTC] johannes@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

Escencially this situation:

<?php
namespace A;
class C {}
function f(A\C $ab) {}

namespace C;
\A\f(new \A\C);

Catchable fatal error: Argument 1 passed to A\a() must be an instance of A\A\b, instance of A\B given, called in Command line code on line 1 and defined in Command line code on line 1
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 11:01:30 2024 UTC