简体   繁体   中英

Using a function before defining it in PHP

in C++, all functions must be defined before using them. In PHP, can I use a function before defining it? Will it be slower?

Since PHP is an interpreted language—not a compiled one—the order does not usually matter, since the contents of the script are parsed prior to the code being executed. There are a few exceptions, particularly when the existence of a function is conditional on some other code being executed.

You can read about this topic in the PHP manual here: http://www.php.net/manual/en/functions.user-defined.php

In C++, we need to declare a function before using it. Not so in PHP: functions need not be defined before they are referenced.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM