Reply to comment

PHP Classes, Calling Parent Methods

This is a followup to [PHP Constructors, Cascading Them].

This example just shows how to call the parent class constructor, and then call the parent class function. (I used this code to experiment with different ways to create the Base object.)

class Base {
	var $x = 'object exists';
	function Base()
	{
		print "Base called.";
	}

	function foo()
	{
		print "Base::foo $this->x";
	}
}
class Ext extends Base
{

	function Ext()
	{
		parent::Base();
	}
	function foo()
	{
		parent::foo();
	}
}

$s = new Ext();

$s->foo();

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul> <p> <br> <div> <pre> <code> <img><h1><h2><h3><h4> <blockquote>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

.