Domanda

I have been looking for an error in my code since an hour. This was the error:

Writing:

if(isset(($_POST['to'])))

instead of

if(isset($_POST['to']))

I don't get why is this extra pair of brackets causing an Internal Server Error.

I don't think putting brackets around a variable never changes its value. I mean,

$a = $b;
$c = ($b);

$a==$c; //True

I am curious as to know why is it an error?

Thank you.

EDIT:

The above error was occurring for normal variable also.

È stato utile?

Soluzione

This is because isset is not a function but a language construct; as such, its definition can be found in the language parser.

T_ISSET '(' isset_variables ')' { $$ = $3; }

It only expects one pair of braces; passing another pair will cause a parse error.

Altri suggerimenti

Im pretty sure it has something to do with the fact that isset can not take a function in parameter. You have to pass it a value. Your extra pair of parenthesis may be evaluated as a 'function' or something that need to be evaluated.

Normally, when you try to pass a function to isset, you get this error :

Can't use method return value in write context

isset:

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.

Information can be passed to functions through arguments. An argument is just like a variable.

Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just seperate them with a comma.

The following example has a function with one argument ($fname). When the familyName() function is called, we also pass along a name (e.g. Jani), and the name is used inside the function, which outputs several different first names, but an equal last name:

<?php
function familyName($fname)
{
echo "$fname Refsnes.<br>";
}

familyName("Jani");
familyName("Hege");
familyName("Stale");
familyName("Kai Jim");
familyName("Borge");
?>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top