cfi*_*her 179 php fatal-error
我收到了这个错误,我无法做出它的头或尾.
确切的错误消息是:
致命错误:第48行/home/curricle/public_html/descarga/index.php中的写入上下文中无法使用函数返回值
第48行是:
if (isset($_POST('sms_code') == TRUE ) {
Run Code Online (Sandbox Code Playgroud)
谁知道发生了什么?
PS这是完整的功能,如果有帮助:
function validate_sms_code() {
$state = NOTHING_SUBMITED;
if (isset($_POST('sms_code') == TRUE ) {
$sms_code = clean_up($_POST('sms_code'));
$return_code = get_sepomo_code($sms_code);
switch($return_code) {
case 1:
//no error
$state = CORRECT_CODE;
break;
case 2:
// code already used
$state = CODE_ALREADY_USED;
break;
case 3:
// wrong code
$state = WRONG_CODE;
break;
case 4:
// generic error
$state = UNKNOWN_SEPOMO_CODE;
break;
default:
// unknown error
$state = UNKNOWN_SEPOMO_CODE;
throw new Exception('Unknown sepomo code: ' . $return_code);
break;
}
} else {
$state = NOTHING_SUBMITED;
}
dispatch_on_state($state);
}
Run Code Online (Sandbox Code Playgroud)
小智 490
在函数返回上使用empty时也会发生这种情况:
!empty(trim($someText)) and doSomething()
Run Code Online (Sandbox Code Playgroud)
因为empty不是一个函数而是一个语言构造(不确定),它只需要变量:
对:
empty($someVar)
Run Code Online (Sandbox Code Playgroud)
错误:
empty(someFunc())
Run Code Online (Sandbox Code Playgroud)
从PHP 5.5开始,它支持的不仅仅是变量.但如果您在5.5之前需要它,请使用trim($name) == false.从空文档.
cha*_*aos 111
你的意思是
if (isset($_POST['sms_code']) == TRUE ) {
Run Code Online (Sandbox Code Playgroud)
虽然顺便说一句,你的意思是
if(isset($_POST['sms_code'])) {
Run Code Online (Sandbox Code Playgroud)
Tig*_*ger 22
if (isset($_POST('sms_code') == TRUE ) {
Run Code Online (Sandbox Code Playgroud)
将此行更改为
if (isset($_POST['sms_code']) == TRUE ) {
Run Code Online (Sandbox Code Playgroud)
你正在使用parentheseis(),$_POST但你想要方括号[]
:)
要么
if (isset($_POST['sms_code']) && $_POST['sms_code']) {
//this lets in this block only if $_POST['sms_code'] has some value
Run Code Online (Sandbox Code Playgroud)
T.T*_*dua 13
代替:
if (empty(get_option('smth')))
Run Code Online (Sandbox Code Playgroud)
应该:
if (!get_option('smth'))
Run Code Online (Sandbox Code Playgroud)
mid*_*dus 11
正确的语法(最后你的括号丢失):
if (isset($_POST['sms_code']) == TRUE ) {
^
Run Code Online (Sandbox Code Playgroud)
ps你不需要 == TRUE 部分,因为已经返回BOOLEAN(true/false).
这种情况可能会在多种情况下发生,下面列出了一些众所周知的情况:
// calling empty on a function
empty(myFunction($myVariable)); // the return value of myFunction should be saved into a variable
// then you can use empty on your variable
Run Code Online (Sandbox Code Playgroud)
// 使用括号访问数组的元素,括号用于调用函数
if (isset($_POST('sms_code') == TRUE ) { ...
// that should be if(isset($_POST['sms_code']) == TRUE)
Run Code Online (Sandbox Code Playgroud)
当我们尝试增加如下函数的结果时,也可能会触发此操作:
$myCounter = '356';
$myCounter = intVal($myCounter)++; // we try to increment the result of the intVal...
// like the first case, the ++ needs to be called on a variable, a variable should hold the the return of the function then we can call ++ operator on it.
Run Code Online (Sandbox Code Playgroud)