My colleague and I have encountered some rather odd behavour. Our environments are Ubuntu 11.10, PHP 5.3.6-13ubuntu3.6 with Suhosin-Patch, and Windows 7 PHP 5.3.5.
On our machines, the following code runs as one would expect:
<?php
function t() { }
var_dump(is_callable('/'));
With the output:
bool(false)
On one of our servers, CentOS release 5.7 (Final), PHP 5.3.8, the same code produces:
bool(true)
Without the t()
function, is_callable
performs as expected. Note that is_function
behaves the same as is_callable
in these tests.
Does anyone have any idea what could be causing this?
Edit:
It seems to only happen when a function named t
is present, anything else, like b
, c
etc, and the output is as expected.
Edit – testing with more characters:
<?php
function t() { }
foreach(str_split('/[email protected]#$%^&*()-_+=`~;:[]{}\|\'"?.>,<') as $character) {
if (is_callable($character)) var_dump($character, is_callable($character));
}
Outputs the following on the server:
string(1) "/"
bool(true)
string(1) "t"
bool(true)
string(1) "T"
bool(true)
string(1) "_" // gettext
bool(true)
string(1) ":" // With the t() function undefined, this remains callable on the server
bool(true)
On our environments, the output is as expected:
string(1) "t"
bool(true)
string(1) "T"
bool(true)
Edit – more information on cbuckley’s comment:
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
function t() { }
$v = '/'; $v();
Produces output: Call to undefined function /()
As a work around you could try this:
$name = '/';
$actual = null;
if (is_callable($name, false, $actual) && $name === $actual) {
// Method is actually callable
}
Tags: phpphp