Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.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 T_PUBLIC,应为使用require()的T_字符串_Php_Require - Fatal编程技术网

Php T_PUBLIC,应为使用require()的T_字符串

Php T_PUBLIC,应为使用require()的T_字符串,php,require,Php,Require,我通过require链接到我的函数时出错 错误:解析错误:语法错误,意外的T_PUBLIC,第3行的/home/content/23/9953123/html/new/lib/functions.php中应为T_字符串 代码: functions.php: <?php function stateToAbb($input){ //reset found $found = 0; //list states $states = "Alaska,Alabama,Arkansas,Ari

我通过require链接到我的函数时出错

错误:解析错误:语法错误,意外的T_PUBLIC,第3行的/home/content/23/9953123/html/new/lib/functions.php中应为T_字符串

代码:

functions.php:

<?php

function stateToAbb($input){ 
//reset found 
$found = 0; 
//list states 
$states = "Alaska,Alabama,Arkansas,Arizona,California,Colorado,Connecticut,Delaware,Florida,Georgia,Hawaii,Iowa,Idaho,Illinois,Indiana,Kansas,Kentucky,Louisiana,Massachusetts,Maryland,Maine,Michigan,Minnesota,Missouri,Mississippi,Montana,North Carolina,North Dakota,Nebraska,New Hampshire,New Jersey,New Mexico,Nevada,New York,Ohio,Oklahoma,Oregon,Pennsylvania,Rhode Island,South Carolina,South Dakota,Tennessee,Texas,Utah,Virginia,Vermont,Washington,Wisconsin,West Virginia,Wyoming"; 
//list abbreviations 
$abb = "AK,AL,AR,AZ,CA,CO,CT,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VA,VT,WA,WI,WV,WY"; 
//create arrays 
$states_array = explode(",", $states); 
$abb_array = explode(",", $abb); 

//run test 
for ($i = 0; $i < count($states_array); $i++){ 
    if (strtolower($input) == strtolower($states_array[$i])){ 
        $found = 1; 
        $output = $abb_array[$i]; 
        return $output; 
    } 
} 
if ($found != 1){ 
    $output = $input; 
    return $output; 
} 
return $output; 
} 

?>
但是,当我只是把函数放在文件中而不需要单独的php文件时,它就可以正常工作了

有什么想法吗

更新

因为每个人都认为我是在尝试快速使用不同的代码。。。 这是一个更新的代码

<?php
require("lib/functions.php");
require("lib/dbconnect.php");
function stateToAbb($input) { 
    //reset found 
    $found = 0; 
    //list states 
    $states = "Alaska,Alabama,Arkansas,Arizona,California,Colorado,Connecticut,Delaware,Florida,Georgia,Hawaii,Iowa,Idaho,Illinois,Indiana,Kansas,Kentucky,Louisiana,Massachusetts,Maryland,Maine,Michigan,Minnesota,Missouri,Mississippi,Montana,North Carolina,North Dakota,Nebraska,New Hampshire,New Jersey,New Mexico,Nevada,New York,Ohio,Oklahoma,Oregon,Pennsylvania,Rhode Island,South Carolina,South Dakota,Tennessee,Texas,Utah,Virginia,Vermont,Washington,Wisconsin,West Virginia,Wyoming"; 
//list abbreviations 
$abb = "AK,AL,AR,AZ,CA,CO,CT,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VA,VT,WA,WI,WV,WY"; 
//create arrays 
$states_array = explode(",", $states); 
$abb_array = explode(",", $abb); 

//run test 
for ($i = 0; $i < count($states_array); $i++){ 
    if (strtolower($input) == strtolower($states_array[$i])){ 
        $found = 1; 
        $output = $abb_array[$i]; 
        return $output; 
    } 
} 
if ($found != 1){ 
    $output = $input; 
    return $output; 
} 
return $output; 
} 
?>

当我删除requirelib/functions.php时,它不起作用;它可以工作,因此问题在于这一行代码调试的第一步:更改某些内容以查看错误消息是否也会更改

我总是通过在错误行之前添加一个空行来确保我查看的是正确的文件。如果错误消息发生相应的更改,我知道我有正确的文件

之后,根据我收到的错误消息,如果代码崩溃,我可能会插入die。对于解析错误,在某些位置添加Semikolon可能会有所帮助


为了确定错误在一行中的确切位置,我通常将这行中的每个关键字拆分为一行。对于解析来说,空白是没有问题的,但是这样做可以更好地识别解析器抱怨的确切位置。

1。所以不是你的个人解析器2。我相信你显示了不同的文件显示的代码没有问题,试着发布另一个文件。我只是猜测:你有一个公共函数foobar{/*code*/}在类之外的某个地方。这是不可能的,不允许的,除此之外,它甚至没有多大意义:如果我删除requirelib/functions.php,则在顶部复制php的完整部分;页面加载正常,上面的文本就是functions.php文件中的全部内容。您确定向我们显示了正确的文件吗?我注意到你的路径包括html/new/也许你在看“html/old”?
<?php
require("lib/functions.php");
require("lib/dbconnect.php");
function stateToAbb($input) { 
    //reset found 
    $found = 0; 
    //list states 
    $states = "Alaska,Alabama,Arkansas,Arizona,California,Colorado,Connecticut,Delaware,Florida,Georgia,Hawaii,Iowa,Idaho,Illinois,Indiana,Kansas,Kentucky,Louisiana,Massachusetts,Maryland,Maine,Michigan,Minnesota,Missouri,Mississippi,Montana,North Carolina,North Dakota,Nebraska,New Hampshire,New Jersey,New Mexico,Nevada,New York,Ohio,Oklahoma,Oregon,Pennsylvania,Rhode Island,South Carolina,South Dakota,Tennessee,Texas,Utah,Virginia,Vermont,Washington,Wisconsin,West Virginia,Wyoming"; 
//list abbreviations 
$abb = "AK,AL,AR,AZ,CA,CO,CT,DE,FL,GA,HI,IA,ID,IL,IN,KS,KY,LA,MA,MD,ME,MI,MN,MO,MS,MT,NC,ND,NE,NH,NJ,NM,NV,NY,OH,OK,OR,PA,RI,SC,SD,TN,TX,UT,VA,VT,WA,WI,WV,WY"; 
//create arrays 
$states_array = explode(",", $states); 
$abb_array = explode(",", $abb); 

//run test 
for ($i = 0; $i < count($states_array); $i++){ 
    if (strtolower($input) == strtolower($states_array[$i])){ 
        $found = 1; 
        $output = $abb_array[$i]; 
        return $output; 
    } 
} 
if ($found != 1){ 
    $output = $input; 
    return $output; 
} 
return $output; 
} 
?>