php - PHP在类if语句中声明方法
问题描述
在 PHP 中,只有当语句为 true 时才可以在类中声明方法:
class MyClass {
//...
if (mode === 'production'):
public function myMethod() {
// My cool stuffs here
}
endif;
}
解决方案
不,你不能,但肯定有一些替代解决方案,比如使用继承。
推荐阅读
- azure - 如何将存储在 VS 中 local.settings.json 中的 SignalRConnectionString 上传到 Azure 门户上的 Azure 函数
- c# - 如何用存储过程返回的数据填充组合框?
- c# - 在 .NET Core 3.0 WinForms 应用程序中注册用于依赖注入的 Serilog 文件记录器
- meteor - Meteor DDP 调用在太长时返回未定义
- .net - inno setup 检查 dotnet core 是否安装
- excel - 如何处理数据集中的空白单元格
- java - Docker 将 Javafx 添加到 openJDK
- jquery - jquery在水平滚动时获取图像偏移量
- ios - 如何在 UITableView (Swift) 中创建可点击的单元格
- javascript - IActiveScriptParse32::ParseScriptText 内存泄漏