php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40136 ReflectionClass::implementsInterface() thowing exception
Submitted: 2007-01-15 19:27 UTC Modified: 2007-01-15 19:42 UTC
From: mark dot 2391 at blueyonder dot co dot uk Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.0 OS: Debian GNU/Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mark dot 2391 at blueyonder dot co dot uk
New email:
PHP Version: OS:

 

 [2007-01-15 19:27 UTC] mark dot 2391 at blueyonder dot co dot uk
Description:
------------
The ReflectionClass::implementsInterface() correctly returns boolean true for a given interface the subject class implements, but instead of returning boolean false for one it does not, a ReflectionException is thrown instead.

Reproduce code:
---------------
<?php

interface Polite
{
    public static function sayHello();
}

class Greeting implements Polite
{
    public static function sayHello()
    {
        echo "Hello<br>\n";
    }
}

Greeting::sayHello();
$refl = new ReflectionClass('Greeting');

if ($refl->implementsInterface('Polite')) {
    echo "Greeting implements Polite<br>\n";
} else {
    echo "Greeting does not implements Polite<br>\n";
}


if ($refl->implementsInterface('Rude')) {
    echo "Greeting implements Rude<br>\n";
} else {
    echo "Greeting does not implement Rude<br>\n";
}
?>

Expected result:
----------------
Hello
Greeting implements Polite
Greeting does not implement Rude

Actual result:
--------------
Hello
Greeting implements Polite

Fatal error: Uncaught exception 'ReflectionException' with message 'Interface Rude does not exist' in /home/mim/sites/intranet.home/tech/PHP/static-classes/static-object-usage.php:26 Stack trace: #0 /home/mim/sites/intranet.home/tech/PHP/static-classes/static-object-usage.php(26): ReflectionClass->implementsInterface('Rude') #1 {main} thrown in /home/mim/sites/intranet.home/tech/PHP/static-classes/static-object-usage.php on line 26

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-15 19:42 UTC] tony2001@php.net
>but instead of returning boolean false for one it does
>not, a ReflectionException is thrown instead.

ReflectionClass::implementsInterface() throws exception only if the interface does not exist and this is expected.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 17 17:01:29 2024 UTC