Wednesday, April 7, 2010

PHP's case sensitivity in function names

Hi Everyone,

Just thought I'd toss out a random tidbit. I've found a program that tried to define a function name that conflicted with a global function name, but not like you would expect.

They used camel case for the function name, when the system defined function didn't. Unfortunately function names in PHP are NOT case sensitive, as shown in the following experiment:


<?php

function test_func() {
echo 'test_func';
}

function Test_Func() {
echo 'Test_Func';
}


Running this script gives:


bill-hamiltons-imac:~ bill$ php test.php

Fatal error: Cannot redeclare test_func() (previously declared in /Users/bill/test.php:4) in /Users/bill/test.php on line 9


So there you have it. PHP function names are not case sensitive which some of you may already know but this is obviously the proof.

Thanks!

No comments:

Post a Comment