如何在PHP中声明函数?

Don*_*oni 0 php function

我想要没有实现的declare功能.实现必须在另一个文件中.

这是否可能,如果是这样,那有什么可靠的吗?通常的做法是这样做吗?我很好奇,因为我来自C++.

例:

----------------- declarations.php -----------

<?php
 function first($name, $age);
 function second($country);
?>
Run Code Online (Sandbox Code Playgroud)

----------------- implementss.php -----------

<?php 
include (declarations.php);

function first($name, $age)
{
 // here is the implementation
}

function second($country)
{
 // here is the other implementation
}
?>
Run Code Online (Sandbox Code Playgroud)

Dan*_*ite 5

我认为你想要的是一个界面,虽然它必须在一个类中实现.

http://php.net/manual/en/language.oop5.interfaces.php

由于PHP是一种脚本语言,因此您仍然必须直接引用该实现include.没有像C++这样的链接阶段.