the web developer

The 21 Most Important Tools and Resources Used In Order to Develop a Website

The Internet today, is full of tools and resources, which can definitely help anyone develop a website. The timeframe that a developer spends on the site, will determine whether or not the website...

improvement

The 101 Most Useful Principles, Which Can Help Improve Your Life Forever

If we ever wondered why your life is not working as it you thought it should, it may be because you need to employ certain actions, which would take you to the next level. In today’s article, we...

Robot assisted surgery

Robot Assisted Surgery Will Change The Medical Field In Surgical Procedures

Robots are an amazing human invention, which we were able to accomplish due to the knowledge and understanding we have about the human body.

In today’s article we are going to talk about...

location based services

Location Based Services Are Changing The Way We Experience Mobile Devices

Our mobile world, has changed and will continue to change in the future; we need to be aware of these changes, so that they don’t catch us by surprise.

In today’s article, we are going to...

sd wan

Software Defined Wide Area Network, is The Future Of Network Infrastructure

Networking professionals have to now change their approach to networking design, due to the rapid change, that is happening in technology.

The introduction of cloud, the changes in IT...

Error message

Notice: Undefined variable: front_page in eval() (line 19 of /home/content/93/10477193/html/modules/php/php.module(80) : eval()'d code).

Object Oriented Programming PHP is A Straight Forward Approach to Programming

php oop

The programming world, is very interesting and many people are always trying to sharpen their skills in the area of programming, or they are trying to acquire new skills in programming.

In today’s article, we are going to talk about, the object-oriented programming side of PHP.

Object Oriented PHP (OO PHP), can have the ability to frighten, many PHP developers.

One of the reasons why, many PHP developers, don’t really like OO PHP, is due to the concepts of complicated syntax and other roadblocks, which they can face, during the development life cycle of applications.

Developers who use OO PHP, are able to group similar programming tasks, into classes.

When tasks are grouped into classes, then the code is not going to be repeated, so that you “don’t repeat yourself” (DRY), also developers can easily maintain their code, when using OO PHP.

Another aspect of your code which, OO PHP can help you with, is that, when updates to your code are required, you can easily change the code, in one central place, and this change will affect the entire code or parts of the code.

Duplicated data and functionality, can affect the code, when it is time to update the code, because a developer, would have to search the entire directory structure, for data.

A lot of developers are intimidated by OOP, due to the new syntax, and when you just look at it, it does look more complicated.

However, OOP is not as bad as many developers, may have in their minds, because this style of programming is a very simple and straightforward approach to programming.

Alright now let’s define some terms, which are useful to know, in order to understand OO PHP.

In OO PHP you will find something known as a Class: which is used by developers, to group local functions and local data.

If you want to make many instances of the same class or kind of objects, then a class would be a handy tool to use.

Another term, to know in OO PHP is the Object: which is defined by the class as an instance of the data structure.

Instances or objects of the same kind, are defined within one class, and the objects can be a combination of variables, functions, and data structures.

Another important term is the Member Variable: which is a variable, which is defined within a class.

Once an object is created, these variables are called attribute of the object.

Also the data contained in these variables, are only seen within the class and not outside of the class, where the variable is located.

Another important term is the Inheritance: which is a class, which has been defined, with an inherited existing function, of a parent class.

Functions and variables of a parent class, are inherited, by the child class, in the process known as inheritance.

Another important term is Polymorphism: which is, a concept in object-oriented programming, which allows the same function, to be used for different purposes.

Encapsulation is another important term in OO PHP, and it refers to objects, which shows that all data and member functions are encapsulated to form that object.

Constructor is important as well, because this is a special type of function, which, whenever there is an object formation from a class, then the constructor is called.

Last but not least, is the Destructor which is a type of function, which, whenever an object is deleted or goes out of scope, then the destructor is called.

Defining PHP Classes

The general form for defining a new class in PHP is as follows –
 

<?php class phpClass { var $var1; var $var2 = "constant string"; function myfunc ($arg1, $arg2) { [.] } [.] } ?>