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
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: 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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 17:01:35 2025 UTC