PHP中的名称空间有什么好处? [英] What's the benefit of namespaces in PHP?

查看:68
本文介绍了PHP中的名称空间有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHP中名称空间的好处是什么?我已经在多个MVC系统上工作,但并没有发现太多用处.我在这里阅读有关它们的信息....这是我从来没有使用过的某种问题吗?经常使用的东西是一种好的编码标准吗?

What's the benefit of namespaces in PHP? I've worked on multiple MVC systems and haven't found much use for them. I'm reading about them here.... is it a problem of sorts that I've never used them? Is it the kind of thing that is a good coding standard to always use?

推荐答案

与其他任何语言一样,名称空间允许歧义名称/具有相同名称的类同时存在于两个不同的名称空间中.

Like any other languages, namespaces allow ambigious names / classes with same name to co-exists while being in two different namespaces.

例如,Table类可以引用持久数据库中的表和HTML表.我可以放置名称空间以专门使用我想要的确切表,即分别为\Model\Table\View\Table.

For example Table class can be referring to a table in a persistent database and a HTML table. I can put namespaces to specifically use the exact table that I want, i.e. \Model\Table and \View\Table respectively.

这篇关于PHP中的名称空间有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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