Ascending Logic Peaks with the Resolution Operator In PHP, the scope resolution operator, or the double colon ::, allows you to access constants, static properties and methods, and overridden properties and methods. We’ve created a couple of constants in our previous articles, but we’ve never actually accessed them. Method Overriding If you’re accessing, for example, a constant outside of the class, you would append the double colon operator to the instantiated object, or even the class name. If you’re accessing the constant or overridden property or method inside of the class, you would use either self, parent, or the static keyword. We’ll cover self and parent in this article;

Breathing Fresh Life into Logic with Method Overrides PHP’s object oriented principles allow for both method overloading and method overriding. You might have heard both of those terms, but don’t know what they mean, so I want to help to differentiate them for you. Method overloading is when you have two methods with the same name but a different number of parameters. In programming languages like Java, this is pretty simple to achieve. You create two methods with the same name and you provide them with a different number of arguments. area(diam) area(length, width) In the example above, we have

Passing Down Code Wisdom through Generations Who would have guessed that PHP supports inheritance? Everyone using PHP since Object Oriented Programming became a thing, that’s who. If you’re not familiar with inheritance in programming, it’s just mimicking real world concepts, primarily ancestral inheritance. You inherit traits or characteristics from your parents, your parents from their parents and so on. You and I share the same traits as all human beings, so our parent class can be Human. In that Human class we can list methods like walking and speaking. Even though we speak different languages, the mechanism is the same.

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