© Frank M. Kromann 2016

Frank M. Kromann, PHP and MySQL Recipes, 10.1007/978-1-4842-0605-8_2

2. Classes and Objects

Frank M. Kromann

(1)Trabuco Canyon, California, USA

Object-oriented programming provides many advantages over procedural programming. It helps with encapsulation when code is shared within a team or between teams and it can help protect elements of the code from being abused. This is especially the case when code is shared in compiled form but the same mechanisms can be applied to a scripting language like PHP. This chapter describes how object-oriented programming works in PHP.

Recipe 2-1. Writing a Simple Class

Problem

PHP can be used as a procedural programming language, but you want to make use of the many features of object-oriented ...

Get PHP and MySQL Recipes: A Problem-Solution Approach, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.