简体   繁体   English

为什么我不能在isset中分配变量? - php

[英]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. 最近,我试图变得棘手,并在isset函数内部分配一个变量。 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. isset是一种语言结构,而不是一种真正的功能。 It is mentioned in the docs: 它在文档中提到:

Warning 警告

isset() only works with variables as passing anything else will result in a parse error. isset()仅适用于变量,因为传递任何其他内容都会导致解析错误。 For checking if constants are set use the defined() function. 要检查是否设置了常量,请使用defined()函数。

You are trying to pass a statement, this might be the reason. 你试图传递一个声明,这可能是原因。 Here is a note I found in php.net manual for isset(). 这是我在php.net手册中找到的一个注释,用于isset()。

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

isset() only works with variables as passing anything else will result in a parse error. isset()仅适用于变量,因为传递任何其他内容都会导致解析错误。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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