严格的类型 [英] Strict types

查看:67
本文介绍了严格的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


一段时间以来我一直希望PHP有(至少可以选择

启用)严格类型。这将有助于大量的BIG

应用程序,并且可能开始逐渐减少数百万行的废话

代码。


PHP是一种很棒的语言,但是大量无能的编码器

绝对没有什么可以帮助语言增长。我知道我们都必须从某个地方开始
,所以请不要认为我是精英主义者,因为我不是b $ b,但有些东西需要要做的就是把那些烂摊子搞得一团糟。


当然这里的承包商目睹了这一点,还是仅仅是我?


什么是其他人的意见?


干杯,


T''rog

Hi All,

For a while now I''ve been wishing PHP had (at least the option to
enable) strict types. It would help a massive amount in BIG
applications, and maybe start to taper the millions of lines of crap
code that''s out there.

PHP is a great language, but the masses of incompetant coders out there
do absolutely nothing to help the language grow. I know we all have to
start somewhere, so please don''t think I''m being eliteist, because I''m
not, but something has to be done to try to fix the mess out there.

Surely the contractors on here have witnessed this, or is it just me?

What is everyone else''s opinion?

Cheers,

T''rog

推荐答案

2006年3月30日星期四00:53:47 -0800,Treefrog写道:
On Thu, 30 Mar 2006 00:53:47 -0800, Treefrog wrote:
一段时间以来我一直希望PHP有(至少可以选择启用)
严格的类型。这将有助于大量的大型应用程序,并且可能开始逐渐减少数百万行的垃圾代码。
For a while now I''ve been wishing PHP had (at least the option to enable)
strict types. It would help a massive amount in BIG applications, and
maybe start to taper the millions of lines of crap code that''s out there.




To说实话,唯一真正的问题是对象。对于大型

应用程序,一致的命名方案有助于简单的变量和

a很多情况下变量不是很重要。


关于对象,PHP5现在有类型提示,确保函数或方法的参数

属于给定类型(类):


功能栏(Foo



To be honest the only real problem is with objects. For large
applications a consistent naming scheme helps with simple variables and in
a lot of cases it''s not really important what the variable is.

With regards to objects, PHP5 now has type hints which ensures a parameter
to a function or method is of a given type (class):

function bar(Foo


foo)

{

...

}


干杯,


Andy


-

Andy Jeffries MBCS CITP ZCE | gPHPEdit首席开发人员
http://www.gphpedit.org | Gnome 2的PHP编辑器
http://www.andyjeffries.co.uk |个人网站和照片

foo)
{
...
}

Cheers,

Andy

--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos


Treefrog写道:
Treefrog wrote:
大家好,

有一段时间了我'一直希望PHP有(至少可以选择启用)严格的类型。这将有助于大量的应用程序,并可能开始逐渐减少数百万行的垃圾代码。

PHP是一种很棒的语言但是那些无能的编码人员群众在这方面做的事情绝对没有任何帮助。我知道我们都必须从某个地方开始,所以请不要认为我是精英主义者,因为我不是,但是必须采取一些措施来解决这个问题在那里。

当然这里的承包商目睹了这一点,还是仅仅是我?

其他人的意见是什么?
干杯,

T''rog
Hi All,

For a while now I''ve been wishing PHP had (at least the option to
enable) strict types. It would help a massive amount in BIG
applications, and maybe start to taper the millions of lines of crap
code that''s out there.

PHP is a great language, but the masses of incompetant coders out there
do absolutely nothing to help the language grow. I know we all have to
start somewhere, so please don''t think I''m being eliteist, because I''m
not, but something has to be done to try to fix the mess out there.

Surely the contractors on here have witnessed this, or is it just me?

What is everyone else''s opinion?

Cheers,

T''rog



好​​吧,你可以通过将所有基本类型包装在类中来实现PHP5中

喜欢java做很多事情。然后每个类型类都有它的

拥有toXXX转换器来处理强制转换。


这是用另一个抽象级别修复的一个例子''而且我想知道这一切的实用性。 PHP - 就像shell一样 - 通常很有吸引力

编码器*因为*它是松散的类型。


我不知道有多少编码器会找到PHP如果他们不得不遵循更严格的对象类型编码,那就很有吸引力。例如:


Well, you could do it in PHP5 by wrapping all the basic types in classes
like java does for a lot of things. Then each type class would have its
own toXXX converters to handle the casts.

This is an example of ''fixed with another level of abstraction'' and I
wonder at the utility of it all. PHP - like shell - is often attractive
to coders *because* it is loosely typed.

I''m not sure how many coders would find PHP as attractive if they had to
follow stricter object type coding. For example:


这篇关于严格的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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