为什么我不能重载PHP中的构造函数? [英] Why can't I overload constructors in PHP?

查看:104
本文介绍了为什么我不能重载PHP中的构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我放弃了所有希望能够在PHP中重载我的构造函数,所以我真正想知道的是为什么。

I have abandoned all hope of ever being able to overload my constructors in PHP, so what I'd really like to know is why.

有没有理由呢?它是否产生固有的错误代码?

Is there even a reason for it? Does it create inherently bad code? Is it widely accepted language design to not allow it, or are other languages nicer than PHP?

推荐答案

您可以使用变量参数以产生相同的效果。没有强类型,添加,默认参数和所有其他工作周围没有什么意义。

You can use variable arguments to produce the same effect. Without strong typing, it doesn't make much sense to add, given default arguments and all of the other "work arounds."

这篇关于为什么我不能重载PHP中的构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆