Hello Derick, Wednesday, March 15, 2006, 10:24:37 AM, you wrote:
> 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 ) ); > ?> > [EMAIL PROTECTED]:/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 I would prefer a slightly different approach and make is_string() return true for both native and unicode strings. This would lead to the following layout: is_string(): Z_TYPE_P() == IS_STRING || Z_TYPE_P() == IS_UNICODE (string): bypass native + unicode, convert according to unicode mode; make_printable_zval is_binary(): Z_TYPE_P() == IS_STRING (binary): bypass native; make_string_zval is_unicode(): Z_TYPE_P() == IS_UNICODE (unicode): bypass unicode: make_unicode_string which to me makes pretty much sense. The point is that we still have automatic conversion mostly everywhere or will get it nearly everywhere sooner or later. So when dealing with a string variable it doesn't really matter what kind it is and if so one has the ability to check for the exact type. Best regards, marcus -- PHP Unicode & I18N Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php