Bug #68041 [Opn->Nab]: Interfaces - Interfaced instance can access undefined methods

From: Date: Thu, 18 Sep 2014 11:13:46 +0000
Subject: Bug #68041 [Opn->Nab]: Interfaces - Interfaced instance can access undefined methods
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187586@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68041&edit=1 ID: 68041 Updated by: johannes@php.net Reported by: sosingus at gmail dot com Summary: Interfaces - Interfaced instance can access undefined methods -Status: Open +Status: Not a bug Type: Bug Package: *General Issues Operating System: Linux PHP Version: 5.4.32 Block user comment: N Private report: N New Comment: 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 . Previous Comments: ------------------------------------------------------------------------ [2014-09-18 09:47:33] sosingus at gmail dot com Description: ------------ If we use interfaced instance to access a method not defined in interface itself, code will work! Expected is RuntimeException of some kind. Same applies for using parent class on instance of some subclass. If anyone cares I'll serach and create similar bug report for classes. This behavior can lead to serious problems in any serious OO code. Worst of all it cannot be predicted in any way. I think this is a system issue and probably exists since the OO beginning in php. Test script: --------------- <?php interface TestInterface { public function printMe(); } class TestClass implements TestInterface { public function printMe() { print "1\n"; } public function printMeToo() { print "2\n"; } } function testInterfaceShouldFail(TestInterface $instance) { $instance->printMe(); $instance->printMeToo(); } testInterfaceShouldFail(new TestClass()); Expected result: ---------------- raised/thrown RuntimeException Actual result: -------------- 1 2 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68041&edit=1

« previous php.bugs (#187586) next »