简体   繁体   English

在PHP中定义之前使用函数

[英]Using a function before defining it in PHP

in C++, all functions must be defined before using them. 在C ++中,必须在使用它们之前定义所有函数。 In PHP, can I use a function before defining it? 在PHP中,我可以在定义之前使用函数吗? 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. 由于PHP是一种解释型语言 - 而不是编译式语言 - 因此在执行代码之前解析脚本的内容并不重要。 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 您可以在PHP手册中阅读有关此主题的信息: http//www.php.net/manual/en/functions.user-defined.php

In C++, we need to declare a function before using it. 在C ++中,我们需要在使用它之前声明一个函数。 Not so in PHP: functions need not be defined before they are referenced. 在PHP中不是这样:函数在引用之前不需要定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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