note 107451 added to keyword.extends

From: Date: Fri, 10 Feb 2012 06:27:05 +0000
Subject: note 107451 added to keyword.extends
Groups: php.notes 
Request: Send a blank email to php-notes+get-186045@lists.php.net to get a copy of this message
I have found this the best way to grab a parents variables and such (that I love to set in the constructor, like standardized table names, etc.). I just call the parents constructor in the child constructor, then change variables inside the child constructor that needs to be customized for that class, or just leave it alone to make sure I understand I am using the parents constructor in the child constructor. (it's a good note and practice of mine.). class MyParentClass { $this->table_one = "my_table"; $this->table_two = "variable_table"; } class MyChildClass extends MyParentClass { public function construct() { parent::__construct(); $this->table_two = "newly_defined_table"; } public function action() { $table1 = $this->table_one; $table2 = $this->table_two; return $table1 . " - " . $table2; } } $myChildClass = new MyChildClass; echo $myChildClass->action(); //Displays my_table - newly_defined_table ---- Server IP: 69.147.83.197 Probable Submitter: 99.108.96.121 ---- Manual Page -- http://www.php.net/manual/en/keyword.extends.php Edit -- https://master.php.net/note/edit/107451 Del: integrated -- https://master.php.net/note/delete/107451/integrated Del: useless -- https://master.php.net/note/delete/107451/useless Del: bad code -- https://master.php.net/note/delete/107451/bad+code Del: spam -- https://master.php.net/note/delete/107451/spam Del: non-english -- https://master.php.net/note/delete/107451/non-english Del: in docs -- https://master.php.net/note/delete/107451/in+docs Del: other reasons-- https://master.php.net/note/delete/107451 Reject -- https://master.php.net/note/reject/107451 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186045) next »