manokarthick karthick manokarthick karthick - 5 months ago 15
PHP Question

how to display string with echo that has die function

echo 'SKU is B001'.die();


in the above line due to die at end, the echo not displays the string.

how die works here?

Answer

The order of evaluation is as following:

echo('SKU is B001'.die());

PHP needs to evaluate the parameter for echo before it can call echo:

'SKU is B001'.die()

The . operator now needs to evaluate 'SKU is B001', which is just 'SKU is B001' and the result of die() before it can concatenate the strings;

Once it calls die, the execution of the program stops.