[TYPO3-50-general] PHP6 array keys unicode issue

Elmar Hinz elmar.DOT.hinz at team.MINUS.red.DOT.net
Wed Jun 13 14:59:24 CEST 2007


Am Wed, 13 Jun 2007 14:52:12 +0200 schrieb Robert Lemke:

> Hey bleeding-edge-PHP-users,
> 
> I just stumbled over a weird behaviour with PHP6. Consider the  
> following code (with unicode_semantics
> enabled):
> 
> <?php
> preg_match('/(?P<character>\w),/', 'a,b,c,d', $matches);
> echo (isset($matches[(binary)'character']) ? 'yes ' : 'no ');
> echo (isset($matches[(unicode)'character']) ? 'yes ' : 'no ');
> 
> $matches = array('character' => 'a');
> echo (isset($matches[(binary)'character']) ? 'yes ' : 'no ');
> echo (isset($matches[(unicode)'character']) ? 'yes ' : 'no ');
> ?>
> 
> The regular expression creates an associative array with "character"  
> as the key.
> My expected output is:
> 
> no yes no yes
> 
> But it is
> 
> yes no no yes
> 
> The preg_match seems to use a "binary" string as the index while my  
> manual assignment
> uses a unicode string.
> 
> The question is if that is a wanted behaviour and if we can rely on  
> that. I just wanted
> to hear your opinion about it before I ask in one of the PHP lists ...
> 
> robert

Hi Robert, 

I don't know PHP6. Things may be different. But in PHP4 I wouldn't
expect to have characters as keys of $matches. I expect integers. 

0 for the whole matched string. 1 for the first hit, 2 for the second and
so on.

Regards

Elmar


More information about the TYPO3-project-5_0-general mailing list