Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is PHP Object-oriented?

Is PHP an object-oriented language? If not, then what about the framework CakePHP? Is it an object-oriented MVC implementation of PHP?

Also, can a PHP application wholly built using classes be called object-oriented?

like image 866
avon_verma Avatar asked Jan 15 '11 12:01

avon_verma


People also ask

Is PHP object oriented or procedural?

However, sometimes using object oriented programming requires more effort than it's worth. In fact, PHP was initially developed as a procedural language and only later extended to OOP. PHP programmers cannot agree on which style is preferable.

Does PHP have object-oriented programming?

PHP is a server-side scripting language, mainly used for web development but also used as a general-purpose programming language. Object-Oriented Programming (PHP OOP), is a type of programming language principle added to php5, that helps in building complex, reusable web applications.

When did PHP get OOP?

This PHP OOP series helps you master Object-oriented Programming in PHP. PHP introduced object-oriented programming features since version 5.0.


1 Answers

No, PHP is not fully object oriented language.

And neither is C++ or Java, because they all have primitive types (and PHP also has a huge collection of function like str_replace() and is_*(), which are clearly procedural in nature). Only pure object-oriented language, that i know of, are Ruby and Scala (and one could argue that latter is more aiming at functional programming paradigm).

PHP is, what one could call, "object-capable language".

As for the code written in PHP, you have to understand that just because you are using classes, it does not make it OOP. Especially if your code is mostly based on static class.

So, if you ask: "is CakePHP an OO framework?", then the answer is - NO. The most flattering description for it would be "class oriented programming". The code-base is filled with static methods and variables, where class acts more like a namespace. Basically CakePHP is a procedural code, wrapped in syntax, which on surface mimics object oriented code.

like image 105
tereško Avatar answered Sep 20 '22 18:09

tereško