Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using hash in PHP's function call? [closed]

Tags:

function

php

Yesterday I took a part in interview for PHP developer postion. My job was to solve 15 questions in quite simple test. One of the questions was to mark all places, in given example PHP code, where execution would be stopped with fatal error. Among others, I marked as wrong something like that:

$this->someFunction(#);

The other person on interview told me, that I was wrong, because this is not a fatal error.

Can someone enlight me, why and how do we use hashes (#) in PHP function calls? I have never seen a construction like that and Google told me less than nothing on this (or maybe I did incorrect search).

like image 552
trejder Avatar asked Oct 26 '12 20:10

trejder


2 Answers

The # character is used for single-line comments.

It would be a syntax error on its own because there would be no )

$this->someFunction(#);

This is read as:

$this->someFunction(

But, if there are lines after this, then it's ok. Example:

$this->someFunction(#);
    'a', 'b', 'c'
);

The #); is a comment, and not parsed, so PHP sees

$this->someFunction(
    'a', 'b', 'c'
);

Which is valid.

like image 65
Rocket Hazmat Avatar answered Oct 22 '22 06:10

Rocket Hazmat


This will cause a 'parse error', not fatal. just simply check it yourself.

like image 25
Headshota Avatar answered Oct 22 '22 05:10

Headshota