简体   繁体   中英

Why can't I assign a variable inside of isset? - php

Recently, I've attempted to be tricky and assign a variable inside of an isset function. I tried to do it like so

if(isset($accountid =$_POST['Recipient']))
{
    // my code here ... 
} 

However, when I do this I receive the error

syntax error, unexpected '=', expecting ',' or ')'

Here is the documentation for isset if you want to reference it in your answer. bool isset ( mixed $var [, mixed $... ] )

This isn't the hugest deal - but I'd be interested to know why I can't do something along those lines!

isset is a language construct and not a true function. It is mentioned in the docs:

Warning

isset() only works with variables as passing anything else will result in a parse error. For checking if constants are set use the defined() function.

You are trying to pass a statement, this might be the reason. Here is a note I found in php.net manual for isset().

http://php.net/manual/en/function.isset.php

isset() only works with variables as passing anything else will result in a parse error.

您正在执行一个操作,该操作不会返回指向期望函数的函数中的变量的指针。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM