6

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!

1
  • if($accountid=isset($_POST['Recipient'])?$_POST['Recipient']:false){echo $accountid;} Commented Jul 16, 2014 at 12:45

3 Answers 3

7

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

You're putting an operation that doesn't return a pointer to a variable in a function that expects one.

2 Comments

Yes, and what should the point with if(isset($accountid =$_POST['Recipient'])) instead of if(isset($_POST['Recipient'])) be anyway?
This is wrong. If the problem was passing by reference you'd get a different error message, this is about how isset is built into PHP. 3v4l.org/6v9hh Fatal error: Only variables can be passed by reference in /in/6v9hh on line 11

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.