#35363 [Opn->Bgs]: Type Hinting doesn't work with strings

From: Date: Thu, 24 Nov 2005 12:26:39 +0000
Subject: #35363 [Opn->Bgs]: Type Hinting doesn't work with strings
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-88839@lists.php.net to get a copy of this message
ID: 35363 Updated by: tony2001@php.net Reported By: mg at memedia dot de -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: Various PHP Version: 5CVS-2005-11-24 (snap) New Comment: No bug here. Only arrays and classes can be used for typehinting. Previous Comments: ------------------------------------------------------------------------ [2005-11-24 12:50:36] mg at memedia dot de Description: ------------ See above. Maybe there are als osome other variable types that doesn't work. Actually I only see that Classes and Arrays work. Anyway, llive could be easier if I wouldn't need to tell every function to check for incoming variable types ;) Reproduce code: --------------- class Tasty { function mustBeArray(Array $test) { echo "Tasty::mustBeArray\n"; return true; } function mustBeString(String $str) { print("Tasty::mustBeString\n"); } function testType($type){ print("Tasty::testType\n"); print(gettype($type)."\n"); } } $t = new Tasty(); $t->mustBeArray(Array(1,2)); $t->testType((String)'test'); $t->mustBeString((String)'test'); // doesn't work Expected result: ---------------- OUTPUT: Tasty::mustBeArray Tasty::testType string Tasey::mustBeString Actual result: -------------- OUTPUT: Tasty::mustBeArray Tasty::testType string Fatal error: Argument 1 passed to Tasty::mustBeString() must be an object of class String ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=35363&edit=1

« previous php.bugs (#88839) next »