我今天在我们的一些 PHP 代码中遇到了一个非常奇怪的行为。我们有一个处理文件的类。是这样的:
class AFile {
//usual constructor, set and get functions, etc.
//...
public function save() {
//do some validation
//...
if($this->upload()) { //save the file to disk
$this->update_db(); //never reached this line
}
}
private function upload() {
//save the file to disk
//...
return ($success) ? true : false;
}
}
它对我们来说看起来很正常,但是 $this->upload() 函数只返回 NULL 之外的任何内容。我们检查了正确的功能正在运行。我们在它返回之前回显了它的返回值。我们尝试只返回一个真值,甚至是一个字符串。一切都检查正确。但是 $this->upload 仍然评估为 NULL。此外,日志中没有任何内容,并且 ERROR_ALL 已打开。
恼怒的是,我们将函数名称更改为 foo_upload。突然间,一切都奏效了。“上传”不在PHP 保留字列表中。任何人有任何想法为什么名为“上传”的类函数会失败?