我想要没有实现的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)
我认为你想要的是一个界面,虽然它必须在一个类中实现.
http://php.net/manual/en/language.oop5.interfaces.php
由于PHP是一种脚本语言,因此您仍然必须直接引用该实现include.没有像C++这样的链接阶段.
| 归档时间: |
|
| 查看次数: |
506 次 |
| 最近记录: |