is_string()

From: Date: Wed, 15 Mar 2006 09:24:37 +0000
Subject: is_string()
Groups: php.i18n 
Request: Send a blank email to php-i18n+get-978@lists.php.net to get a copy of this message
Hello! The past few days I've been trying to get some of our code to run on PHP 6 with unicode semantics turned on to be able to provide some benchmarking. Ofcourse I found some BC breaking behavior, where the following one is bringing the largest WTF factor: <?php $str = "hautamaekki"; var_dump( is_string( $str ) ); ?> derick@tequila:/tmp$ php-6.0dev /tmp/string-test.php bool(false) (The reason for this is that is_string() now returns true for *binary* strings only). I prepared a patch [1] which reverts is_string() back to the "expected" behavior. This patch is also in line with the notes from the PDM [2]. Andrei argued that is_string() and (string) should work on binary strings and is_unicode() and (unicode) for "real" strings. However I think it is a much better idea to use is_binary()/(binary) and is_string()/(string) instead as this will not break so much code. To illustrate this with another example that I encountered in PHPUnit2 when trying to get our code running: In Framework/TestSuite.php there is the following code (shortened): public function __construct($theClass = '', $name = '') { $argumentsValid = FALSE; if (is_object($theClass) && $theClass instanceof ReflectionClass) { $argumentsValid = TRUE; } else if (is_string($theClass) && $theClass !== '' && class_exists($theClass)) { Which is f.e. called with (ezcTestSuite inherits the PHPUnit2 TestSuit class): public static function suite() { return new ezcTestSuite( "ezcConsoleToolsInputTest" ); } This does not work anymore with PHP 6 as the string is now suddenly no string anymore... highlight confusing I would say. Can we please use is_binary()/(binary) for binary string types and is_string()/(string) for real strings as per PDM notes? regards, Derick [1] http://files.derickrethans.nl/patches/uc-is_string-2006-03-15.diff.txt [2] http://www.php.net/~derick/meeting-notes.html#different-string-types -- Derick Rethans http://derickrethans.nl | http://ez.no | http://xdebug.org

« previous php.i18n (#978) next »