What is the minus sign function in fron of a variable definition in PHP?

I was looking for some PHP code:

<?php -$username = "admin"; -$password = "secret"; -$database = "mystore"; mysql_connect("localhost", $username, $password); mysql_select_db($database); 

What is the minus sign function before variable names?

If I do the same in the PHP interpreter, this results in a valid code, and there seems to be no difference:

 $ php -a Interactive shell php > $a=1;echo $a; 1 php > -$a=2;echo $a; 2 

I asked Google, but she could not help me.

+7
php
source share
1 answer

-$username = "admin"; evaluated as - ($username = "admin");

That is, the attached unary operator - applied to the expression.

An expression consists only of assignment.

Thus, the string is assigned to a variable, then, in accordance with the php syntax, the expression returns the same value that is implicitly converted to a number and denied. Then the result is discarded.

Thus, there is no particular significance here; someone accidentally places it.

+9
source share

All Articles