Showing posts from February, 2018

Object Oriented PHP for Beginners

For this tutorial, you should understand a few PHP basics: functions, variables, conditionals and loops. To make things easy, the tutorial is divided into 22 steps. Step 1: First thing we need to do is create two PHP pages: index.php class_lib.php OOP is all about creating modular code, so our object oriented PHP code will be contained in dedicated files that we will then insert into our normal PHP page using php ‘includes’. In this case, all our OO PHP code will be in the PHP file: class_lib.php OOP revolves around a construct called a ‘class’. Classes are the cookie-cutters / templates that are used to define objects. Step 2: Create a simple PHP class (in class_lib.php) Instead of having a bunch of functions, variables and code floating around willy-nilly, to design your php scripts or code libraries the OOP way, you’ll need to define/create your own classes. You define your own class by starting with the keyword ‘class’ followed by the name you want to g