我只想declare
函数没有的实现。这些实现必须位于另一个文件中。如何在PHP中声明函数?
这是可能的,如果是这样,那里有一些棘手的问题吗? 这是否是常见做法?我很好奇,因为我来自C++。
实施例:
----------------- declarations.php -----------
<?php
function first($name, $age);
function second($country);
?>
- --------------- implements.php -----------
<?php
include (declarations.php);
function first($name, $age)
{
// here is the implementation
}
function second($country)
{
// here is the other implementation
}
?>
改为使用'required_once',而且你所做的方式是正确的,但可能不是最佳的。 –
你已经声明了一个函数后就不能重新声明它,所以没有办法做到以上不行。如下所述,尽管交换到OO可能会达到相同的结果。有没有php equivilent的.h :( – Dave