开发者

Can I focus php to type the variable class in php?

In Java, everything object, I know which type it is, for example... I will doing something like this:

MyObject aObject = new MyObject();

I always know that the "aObject" is MyObject...

but PHP, I use this

$aObject = new MyObject();

I don't know what is the "aObject" was, I try to doing this, it gives me error:

MyOb开发者_如何学运维ject $aObject = new MyObject();

It makes me feel very focus on that, any suggestions? Thank you.


You can make great use of comments like that

// data type is MyObject
$aObject = new MyObject();


You might want to read PHP: Type Juggling, and PHP: Type Hinting on php.net.


That is, unfortunatley for you, how PHP works. There are no strict data-types in PHP, what so ever. It is something that you have to grow into to be a PHP-programmer.


No, in PHP you can do Type juggling:

$aObject = new MyObject();
$aObject = new UnrelatedObject();

is perfectly valid PHP. It's not necessarily a bad thing though. It has both pros and cons.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜