可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm getting this error and I can't make head or tail of it.
The exact error message is:
Fatal error: Can't use function return value in write context in /home/curricle/public_html/descarga/index.php on line 48
Line 48 is:
if (isset($_POST('sms_code') == TRUE ) {
Anybody knows what's going on???
PS Here's the full function, in case it helps:
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); }
回答1:
You mean
if (isset($_POST['sms_code']) == TRUE ) {
though incidentally you really mean
if(isset($_POST['sms_code'])) {
回答2:
This also happens when using empty on a function return:
!empty(trim($someText)) and doSomething()
because empty is not a function but a language construct (not sure), and it only takes variables:
Right:
empty($someVar)
Wrong:
empty(someFunc())
Since PHP 5.5, it supports more than variables. But if you need it before 5.5, use trim($name) == false
. From empty documentation.
回答3:
if (isset($_POST('sms_code') == TRUE ) {
change this line to
if (isset($_POST['sms_code']) == TRUE ) {
You are using parentheseis () for $_POST
but you wanted square brackets []
:)
OR
if (isset($_POST['sms_code']) && $_POST['sms_code']) { //this lets in this block only if $_POST['sms_code'] has some value
回答4:
for WORDPRESS:
instead of:
if (empty(get_option('smth')))
should be:
if (!get_option('smth'))
回答5:
Correct syntax (you had a missing parentheses in the end):
if (isset($_POST['sms_code']) == TRUE ) { ^
p.s. you dont need == TRUE
part, because BOOLEAN (true/false) is returned already.
回答6:
This can happen in more than one scenario, below is a list of well known scenarios :
// 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
// using parenthesis to access an element of an array, parenthesis are used to call a function
if (isset($_POST('sms_code') == TRUE ) { ... // that should be if(isset($_POST['sms_code']) == TRUE)
This also could be triggered when we try to increment the result of a function like below:
$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.
回答7:
The problem is in the ()
you have to go []
if (isset($_POST('sms_code') == TRUE)
by
if (isset($_POST['sms_code'] == TRUE)
回答8:
I also had a similar problem like yours. The problem is that you are using an old php version. I have upgraded to PHP 5.6 and the problem no longer exist.
回答9:
Another scenario where this error is trigered due syntax error:
ucwords($variable) = $string;
回答10:
i also ran into this problem due to syntax error. Using "(" instead of "[" in array index:
foreach($arr_parameters as $arr_key=>$arr_value) { $arr_named_parameters(":$arr_key") = $arr_value; }
回答11:
function tracker_printcomments($issueid) { global $CFG, $DB;
$comments = $DB->get_records('tracker_issuecomment', array('issueid' => $issueid), 'datecreated'); //print_object($issueid);
// print_object($comments); $cmnt=''; if ($comments) {
foreach ($comments as $comment) { $user = $DB->get_record('user', array('id' => $comment->userid)); $cmnt .= '<tr>'; $cmnt .= '<td valign="top" class="commenter" width="30%">'; $cmnt .= tracker_print_user($user); //2 $cmnt .= '<br/>'; $cmnt .= '<span class="timelabel">'.userdate($comment->datecreated).'</span>'; $cmnt .= '</td>'; $cmnt .= '<td colspan="3" valign="top" align="left" class="comment">'; //echo '<td colspan="3" valign="bottom" align="left" class="alinks">' ; if($comment->attachmentid) $attachment= $DB->get_records_sql("SELECT * FROM {files} WHERE filename != '.' AND itemid =$comment->attachmentid"); $cmnt .= $comment->comment; //print_object($attachment); //echo '<span colspan="3" valign="bottom" align="left" class="alinks">'; if(!empty($attachment)) { $out = array(); $fs = get_file_storage(); foreach($attachment as $attachments) { $files = $fs->get_area_files($attachments->contextid, 'user', 'draft',$comment->attachmentid, 'id', false); } foreach($files as $file) { $filename = $file->get_filename(); $ctxid = $file->get_contextid(); $component = $file->get_component(); $itemid = $file->get_itemid(); $url = $CFG->wwwroot."/draftfile.php/$ctxid/user/draft/$itemid/$filename"; $out[] = html_writer::link($url, $filename); } $br = html_writer::empty_tag('br'); $cmnt .= implode($br, $out); } //$cmnt= $comment->comment; // $cmnt= '</span>'; $cmnt .= '</td>'; $cmnt .= '</tr>'; } }
return $cmnt;
}
Am also getting same error for this function
Can't use function return value in write context