Inconsistent get_class_methods vs method_exists when using UTF8 characters in PHP code
Posted
by coma
on Stack Overflow
See other posts from Stack Overflow
or by coma
Published on 2010-02-19T11:05:50Z
Indexed on
2010/05/27
0:21 UTC
Read the original article
Hit count: 446
I have this class in a UTF-8 encoded file called EnUTF8.Class.php:
class EnUTF8 {
public function ñññ() {
return 'ñññ()';
}
}
and in another UTF-8 encoded file:
require_once('EnUTF8.Class.php');
require_once('OneBuggy.Class.php');
$utf8 = new EnUTF8();
//$buggy = new OneBuggy();
echo (method_exists($utf8, 'ñññ')) ? 'ñññ() exists!' : 'ñññ() does not exist...';
echo "\n\n----------------------------------\n\n"
print_r(get_class_methods($utf8));
echo "\n----------------------------------\n\n"
echo $utf8->ñññ();
that produces the expected result:
ñññ() exists!
----------------------------------
Array
(
[0] => ñññ
)
----------------------------------
ñññ()
but if...
require_once('EnUTF8.Class.php');
require_once('OneBuggy.Class.php');
$utf8 = new EnUTF8();
$buggy = new OneBuggy();
echo (method_exists($utf8, 'ñññ')) ? 'ñññ() exists!' : 'ñññ() does not exist...';
echo "\n\n----------------------------------\n\n"
print_r(get_class_methods($utf8));
echo "\n----------------------------------\n\n"
echo $utf8->ñññ();
then the weirdness appears!!!:
ñññ() does not exist!
----------------------------------
Array
(
[0] => ñññ
)
----------------------------------
Fatal error: Call to undefined method EnUTF8::ñññ() in /var/www/test.php on line 16
Well, the thing is that OneBuggy.Class.php is UTF-8 encoded too and shares absolutly nothing with EnUTF8.Class.php so...
where is the bug?
UPDATED:
Well, after a long debugging time I found this in OneBuggy.Class.php constructor:
setlocale (LC_ALL, "es_ES@euro", "es_ES", "esp");
so I did...
//setlocale (LC_ALL, "es_ES@euro", "es_ES", "esp");
and now it works but why?.
© Stack Overflow or respective owner