Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is $M-; syntactically valid and what does it do?

Tags:

php

I don't consider myself as PHP expert but I've designed several pages now containing a couple of thousand lines of code each. For my current project which is for a game site I drew back on an existing function which contains the line

$M–;

Now my basic understanding of PHP tells me this doesn't work since it should be -- for short -1. But it's not a dash, the script runs without error (error_reporting (E_ALL)) but echoing $M before and after gives me the same value.

So what does it do and why don't I get an error?

like image 952
Nico Avatar asked Oct 25 '12 09:10

Nico


2 Answers

That's an en dash, which to PHP is just a random byte without specific meaning. $M–, or in UTF-8 encoding 4DE28093, is a valid variable name. Just like $漢字.

A single variable by itself just initializes that variable to null if it doesn't already exist, the line doesn't do anything else.

like image 192
deceze Avatar answered Nov 20 '22 13:11

deceze


That code of your will result in a notice. First because that isn't a minus sign vs - <- different (unless you have a variable name defined M–).

Notice: Undefined variable: M– in

Second even if it was a minus sign it would spit out a notice.

Parse error: syntax error, unexpected ';' in

If anything it only shows you haven't properly enabled full error reporting or that you are using unicode characters in variable names just to screw with other people reading your code (including yourself). ;)

UPDATE

I misread your code a bit. What happens is that you have are initializing the variable M– when doing that line so M– will be null.

like image 25
PeeHaa Avatar answered Nov 20 '22 14:11

PeeHaa