Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 调用未定义函数问题_Php - Fatal编程技术网

Php 调用未定义函数问题

Php 调用未定义函数问题,php,Php,所以我一直在尝试一个测试,因为最近在一个小项目中失败了,我在if语句中创建了一个函数并尝试使用它。我曾尝试在if结构内部和if结构外部使用它,但每次PHP返回一个错误,说“调用未定义的函数” 您可能正在从testing.php内部调用test。判断的简单方法是注释掉对test($name)的调用在您显示的文件中,并观察到相同的错误 如果希望testing.php中的代码利用外部定义的test函数,则需要在加载testing.php之前定义test function test($name){ //

所以我一直在尝试一个测试,因为最近在一个小项目中失败了,我在if语句中创建了一个函数并尝试使用它。我曾尝试在if结构内部和if结构外部使用它,但每次PHP返回一个错误,说“调用未定义的函数”


您可能正在从
testing.php
内部调用
test
。判断的简单方法是注释掉对
test($name)的调用在您显示的文件中,并观察到相同的错误

如果希望
testing.php
中的代码利用外部定义的
test
函数,则需要在加载
testing.php
之前定义
test

function test($name){ // @note Fix the parameter too..
  echo $name;
}
require 'testing.php';

if(isset($_POST['submit'])){
 if(isset($_POST['name']) && !empty($_POST['name'])){
  if(!strpbrk($_POST['name'],'/[!@#$%^*}{};:?/')){

   $name = htmlentities($_POST['name']);

   test($name);
   }else{
    echo 'Please only submit alphanumeric values and underscores.';
   }
    }else{
     echo 'Please enter a name.';
    }
}

您确定它不是在抱怨
strpbrk
而不是
test
?是的。它特别指出“调用未定义的函数test()”您是否试图从
testing.php
内部调用
test
?您在函数中使用$thename作为参数,而$name作为变量。可能无法解决问题,但我打赌如果您执行
test($name)在这里的示例中,代码仍然会出现相同的错误。
function test($name){ // @note Fix the parameter too..
  echo $name;
}
require 'testing.php';

if(isset($_POST['submit'])){
 if(isset($_POST['name']) && !empty($_POST['name'])){
  if(!strpbrk($_POST['name'],'/[!@#$%^*}{};:?/')){

   $name = htmlentities($_POST['name']);

   test($name);
   }else{
    echo 'Please only submit alphanumeric values and underscores.';
   }
    }else{
     echo 'Please enter a name.';
    }
}