我只想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