开发者

object oriented nature of PHP

How does loosely ty开发者_开发问答ped structure of PHP go with object oriented nature of PHP?

Also, is PHP a pure object oriented language?

Thanks in advance.

I meant to point out the loosely typed nature of PHP. I meant the variable declaration, to be precise. How does this drawback of PHP go with its object oriented nature. Does PHP5 have pure object oriented features?


Nope, PHP is not a OOP-only language. In fact, they implemented OOP later on.

The losely typed nature of PHP can be a bitc*, but at the same time it can be very handy. I don't really see a problem with that. If you want to use strict typing, you have to force it in your code. You can explicitely cast variables to a specific type:

$integer = (int) $stringVariableWithIntegerValue;

And you can force a check on type using the === operator. In my opinion PHP is not a complete OOP implementation, but it works pretty well since 5.x.

$integer = 1;
$string = "1";

if($integer === $string) { // Will be false
...

if($integer == $string) { // Will be true
...


I meant to point out the loosely typed nature of PHP. I meant the variable declaration, to be precise. How does this drawback of PHP go with its object oriented nature.

You somehow seem to be under the impression that dynamic typing is a "drawback". It's not, it's just different. It does have its pitfalls, but so does pretty much every type system.

A variable can be any type. It can be an object as well. You can explicitly (manually) type check when you need to. There's syntactic sugar for actual type hinting of objects for function parameters. You can duck type to take real advantage of dynamic typing and objects. Or you can use none of that. It works fine.

Does PHP5 have pure object oriented features?

Define "pure". PHP has objects. PHP is not an object oriented language. And certainly not a "pure" one for that matter. PHP's OOP feels pretty bolted-on (which it is), but it gets the job done without killing kittens.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜