Building Strong Foundations through Declarations If you come from the olden days of PHP, you might have been spoiled by having PHP automatically declare types for you. The convenience is not something you want every time. Sometimes you want to be able to specify what type of data you want to store or return. It is still optional in PHP; it’s up to you whether you want to use it or not. If you do use it, which I encourage you to do so, and you specify the wrong data type, PHP will throw an error. As of PHP 7,

Empowering Objects to Speak with ‘this’ Voice In the previous articles, we’ve seen how we can access the methods inside of the object using the object operator. This is done when an object is instantiated. We’ve already created a Car object and accessed the drive() method. You did this with the object operator, ->, after instantiating the object: $lamborghini->drive(); <?php Class Car { // … public function drive( $is_car_on = false ) { if ( $is_car_on ) { echo “I’m driving”; } else { echo “You gotta turn me on”; } } } $lamborghini = new Car(); $lamborghini->color = “Black”; $lamborghini->make = “Lamborghini”; $lamborghini->model

Conducting Code Harmony through Expert Methods What is a method? In PHP, it’s just a function inside of a class. That’s the easiest way to think about it. You initialize them the exact same way that you would a function, including using the function keyword. PHP – P35: User Defined Functions In object oriented programming, objects can have specific characteristics, but they can also perform specific actions. The actions are represented by methods. Methods can also have visibility modifiers, such as private, protected, and public, but we’ll leave those out of this article and stick to the default public modifier. We’re building on from our previous article and

Keeping Code Grounded in a Sea of Variables Class constants are similar to regular constants with the exception that they live inside the class. Class constants cannot be changed, hence the name constant. They’re declared using the const keyword and are allocated in memory once per class and not each time that you instantiate the object; this is what’s meant when you hear that constants live within the class. They resemble static variables in that sense, but static variables can be modified. To access the class constant, you need to use the class name and the scope resolution operator (double colon). Constants do not

Using Class Blueprints to construct real objects PHP has been an Object Oriented Language since PHP 5. It’s mature, powerful, and there should be no reason for anyone to hate on it any longer. In this article, I go over the differences between objects and classes, do a short introduction to object oriented programming concepts, and create a small introductory class showing class properties, methods, and local variables. Classes vs Objects Imagine that you’re constructing a building. Usually the architect, you as a programmer, will develop a blueprint, the class, and from that blueprint, a building will be constructed, the