Overriding methods, properties, and constants


show more Overriding methods, properties, and constants provides you with in-depth training on Developer. Taught by Jon Peck as part of the Object-Oriented Programming with PHP show less
please wait ...

Overriding methods, properties, and constants

Sometimes, it's useful to be able to change how a child class works. To do that, I'll use an override which is just re-declaring a method, property, or constant. If I was to override a property in a child class, I would just declare the property with the same name in the child. Visibility and overrides are similar to abstraction in that I can change the visibility scope, but I can't make it stricter. Overriding a property is very straightforward. In the child class, declare the property. As a demonstration, open the PARK class, then override the country name with the default, Australia. public $country_name = Australia.

Save, then open the demo script. At the end, add the following: echo <h2> Instantiating AddressPark, $address_park = new AddressParkarray street_ address_1 => 789 Missing Circle; street_address_2 => suite 0, city_name => Hamlet, in subdivision_name => Territory.

We'll echo $address_park, display it, and then debug it. Save, then refresh your b...

Overriding methods, properties, and constants
Video duration: 3m 25s 1h 57m Intermediate Updated Apr 10, 2013

Viewers:

Overriding methods, properties, and constants provides you with in-depth training on Developer. Taught by Jon Peck as part of the Object-Oriented Programming with PHP

Subject:
Developer
Software:
PHP
Author:
please wait ...