is_callable在'/'上的行为

Mic*_*son 30 php

我的同事和我遇到了一些相当奇怪的行为.我们的环境是Ubuntu 11.10,带有Suhosin-Patch的PHP 5.3.6-13ubuntu3.6和Windows 7 PHP 5.3.5.

在我们的机器上,以下代码按预期运行:

<?php
function t() { }
var_dump(is_callable('/'));
Run Code Online (Sandbox Code Playgroud)

随着输出:

bool(false)
Run Code Online (Sandbox Code Playgroud)

在我们的一台服务器上,CentOS发行版5.7(最终版),PHP 5.3.8,相同的代码产生:

bool(true)
Run Code Online (Sandbox Code Playgroud)

没有该t()功能,is_callable按预期执行.请注意,is_function行为与is_callable这些测试中的行为相同.

有谁知道是什么原因引起的?

编辑:

看来,当一个同名函数,只发生t存在,什么都一样b,c等等,并如预期的输出.

编辑 - 使用更多字符进行测试:

<?php
function t() { }
foreach(str_split('/abcdefghijkmnopqrstuvwxyz023456789ABCDEFGHIJKLMNOPQRSTUVXYZ!@#$%^&*()-_+=`~;:[]{}\\|\'"?.>,<') as $character) {
    if (is_callable($character)) var_dump($character, is_callable($character));
}
Run Code Online (Sandbox Code Playgroud)

在服务器上输出以下内容:

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)
Run Code Online (Sandbox Code Playgroud)

在我们的环境中,输出符合预期:

string(1) "t"
bool(true)
string(1) "T"
bool(true)
Run Code Online (Sandbox Code Playgroud)

编辑 - 有关cbuckley评论的更多信息:

<?php 
ini_set('display_errors', 1);
error_reporting(E_ALL);
function t() { }
$v = '/'; $v();
Run Code Online (Sandbox Code Playgroud)

产生输出: Call to undefined function /()

Pet*_*tah 1

作为解决方法,您可以尝试以下操作:

$name = '/';
$actual = null;
if (is_callable($name, false, $actual) && $name === $actual) {
    // Method is actually callable
}
Run Code Online (Sandbox Code Playgroud)