#35363 [NEW]: Type Hinting doesn't work with strings
| From: | mg at memedia dot de | Date: | Thu, 24 Nov 2005 11:50:39 +0000 |
| Subject: | #35363 [NEW]: Type Hinting doesn't work with strings | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-88835@lists.php.net to get a copy of this message | ||
From: mg at memedia dot de
Operating system: Various
PHP version: 5CVS-2005-11-24 (snap)
PHP Bug Type: Scripting Engine problem
Bug description: Type Hinting doesn't work with strings
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 bug report at http://bugs.php.net/?id=35363&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=35363&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=35363&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=35363&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=35363&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=35363&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=35363&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=35363&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=35363&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=35363&r=support
Expected behavior: http://bugs.php.net/fix.php?id=35363&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=35363&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=35363&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=35363&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35363&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=35363&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=35363&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=35363&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=35363&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=35363&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=35363&r=mysqlcfg