Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53674 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67484 invoked from network); 29 Jun 2011 19:39:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jun 2011 19:39:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=ralph@smashlabs.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=ralph@smashlabs.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain smashlabs.com from 67.15.58.61 cause and error) X-PHP-List-Original-Sender: ralph@smashlabs.com X-Host-Fingerprint: 67.15.58.61 openrce.org Linux 2.6 Received: from [67.15.58.61] ([67.15.58.61:57491] helo=users.smashlabs.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8F/76-25278-58F7B0E4 for ; Wed, 29 Jun 2011 15:39:50 -0400 Received: (qmail 28827 invoked from network); 29 Jun 2011 14:39:31 -0500 Received: from ip174-73-14-247.no.no.cox.net (HELO ralph-macbook.local) (174.73.14.247) by smashlabs.com with (AES256-SHA encrypted) SMTP; 29 Jun 2011 14:39:30 -0500 Message-ID: <4E0B7F82.5080006@smashlabs.com> Date: Wed, 29 Jun 2011 14:39:46 -0500 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.9) Gecko/20061207 Thunderbird/1.5.0.9 Mnenhy/0.7.4.666 MIME-Version: 1.0 To: internals CC: Dmitry Stogov , david.zuelke@bitextender.com Content-Type: multipart/mixed; boundary="------------020806020606010404070301" Subject: Fix for #53727 (is_subclass_of resolution with interfaces) From: ralph@smashlabs.com (Ralph Schindler) --------------020806020606010404070301 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi all, Concerning: https://bugs.php.net/bug.php?id=53727 I had put together a quick patch against PHP_5_3 to fix, for what I and others might consider, an issue with is_subclass_of() returning false in this situation: interface A {} class B implements A {} var_dump(is_subclass_of('B', 'A')); // false, should be true It returns false in situations where a class does not have a parent. If a parent currently exists, the above works fine. For example: interface A {} class B implements A {} class C extends B {} var_dump(is_subclass_of('B', 'A')); // true Attached is a patch against PHP_5_3, I can create a patch against PHP_5_4 if need be. I've added a test file and all the current Zend/tests run as expected. Thanks, Ralph --------------020806020606010404070301 Content-Type: text/x-patch; name="fix_is_subclass_of.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fix_is_subclass_of.patch" diff --git a/Zend/tests/is_subclass_of.phpt b/Zend/tests/is_subclass_of.phpt new file mode 100755 index 0000000..325e5e0 --- /dev/null +++ b/Zend/tests/is_subclass_of.phpt @@ -0,0 +1,20 @@ +--TEST-- +is_subclass_of() with class names for target and test should work with interfaces +--INI-- +error_reporting=14335 +--FILE-- + +--EXPECT-- +bool(false) +bool(true) +bool(true) +bool(true) diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 6888b7f..c4031f2 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -844,10 +844,13 @@ static void is_a_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool only_subclass) retval = 0; } else { if (only_subclass) { + if (instance_ce && instance_ce->name == (*ce)->name) { + // return here if the class entry names are the same + RETURN_FALSE; + } + if (!instance_ce) { instance_ce = Z_OBJCE_P(obj)->parent; - } else { - instance_ce = instance_ce->parent; } } else { instance_ce = Z_OBJCE_P(obj); --------------020806020606010404070301--