note 56128 deleted from language.oop5.typehinting by bjori

From: Date: Fri, 14 Apr 2006 14:57:14 +0000
Subject: note 56128 deleted from language.oop5.typehinting by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-108081@lists.php.net to get a copy of this message
Note Submitter: tobias_demuth at web dot de ---- Please note, that type-hinting does not mean type-safety! Although the parameter is forced to be of the hinted type, the function itself could do a call to any subtype's method without a parser error or warning. This might be unexpected for Java-Programmers. An example: I've build an interface, an implementing class and a little bit operating code. The class implements one additional method, this would be found normally in deriving classes (But I wanted to hold the example simple). The implementing class: <?php require_once("Testinterface.php"); class Test implements TestInterface { public function testingA() { echo "A"; } public function testingB() { echo "B"; } } ?> It's interface: <?php interface Testinterface { public function testingA(); // Note that testingB() is NOT defined here! } ?> And the testing-code: <?php require_once("Test.php"); require_once("Testinterface.php"); function foo(Testinterface $test) { $test->testingA(); $test->testingB(); } foo(new Test()); ?> Running the testing-code, you would get the following output: AB This was quit unexpected to me, I hoped for a compiler or parser-error, because my intention was it to hide testingB() from foo() - a common way to do in Java. So, Java-Programers, be prepared.

« previous php.notes (#108081) next »