当前位置: 动力学知识库 > 问答 > 编程问答 >

Explain how this code works in PHP?

问题描述:

Please see the below code this is work perfectly in PHP. Can anyone explain me how this code works. Because in the below code i have declared $caregory_id without semicolon and without any value deceleration. Then also this code work perfectly without any error and var_dump($category_id) returns me an null value.

How php execute this code without semicolon??

<?php

$category_id= //No semicolon

var_dump($category_id); //returns NULL

?>

网友答案:

It works because PHP treats your code like this:

$category_id = var_dump($category_id);

The return value of var_dump() gets assigned to $category_id. Undefined variables in PHP are implicitly set to null, which is what you see in the output of var_dump(). However, you would also get a notice about $category_id not being defined; if you don't see it, you should use this code in your script:

error_reporting(-1);
ini_set('display_errors', 'On');

These settings are also recommended during development as they can catch issues that would otherwise have gone unnoticed on a production machine.

分享给朋友:
您可能感兴趣的文章:
随机阅读: