PHP supports UTF-8 characters in function names!

Apr. 8th, 2009 13:14 by Stéphane de LucaPermalink | TrackBack: https://stephanedeluca.com/trackback/864 — exists for 15 years & 6 months ago

While reworking a function that basically dumps the PHP stack when a crash occures, I came accros an interesting things I silently complain about for the past few years: why the hell I cannot write a function name with accents in there?

Well, the dream comes true in PHP 5.x, here you are, see the function Mélody_είναι_συμπαθητική () which mixes both french accents and greek caharacters -- says: Mélody is friendly.

<?php
// additional code
	
function Mélody_είναι_συμπαθητική($arg="avec un long long long argument qu'il faudrait raccourcir un peu") {

	print dumpPHPStack(false);
	print "nn";
}

function main($arg1, $arg2) {
	print "En PHP 5.x on peut appeler des fonctions ayant des accents...n";
	Mélody_είναι_συμπαθητική("avec un long long long argument qu'il faudrait raccourcir un peu");
}

main('here', "we go");
?>

Which outputs the following:

PHP STACK DUMP
| #	| Line #	| File name										| Function call	
| 1	| 102	| /Users/stephanedeluca/Desktop/phpdump.php	| dumpPHPStack (false)	
| 2	| 109	| /Users/stephanedeluca/Desktop/phpdump.php	| Mélody_είναι_συμπαθητική ("avec un long long long argument qu'il faudrait raccourcir un peu")	
| 3	| 112	| /Users/stephanedeluca/Desktop/phpdump.php	| main ("here", "we go")	

I also tested right-to-left characters such as arabic and it works!

PHP STACK DUMP
|#	|Line #	|File name										|Function call	
|1	|82		|/Users/stephanedeluca/Desktop/phpdump.php		|dumpPHPStack (null)	
|2	|87		|/Users/stephanedeluca/Desktop/phpdump.php		|mélody◊صوفي ()	

I'm really happy about this.