note 77559 added to language.oop5.decon
| From: | (php@ideacode.com) | Date: | Tue, 04 Sep 2007 00:02:22 +0000 |
| Subject: | note 77559 added to language.oop5.decon | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130141@lists.php.net to get a copy of this message | ||
You can pass all arguments from a derived class's constructor to the parent's constructor
using func_get_args(), call_user_func_array(), and parent. For example, say you wanted to add
logging to a class, but let the base do all the usual work:
<?php
class InstrumentedPDO extends PDO {
private $log = null;
public function __construct() {
// connect to logging
require_once('Log.php');
$this->log = Log::factory('display');
// pass through
$args = func_get_args();
call_user_func_array(array (parent, '__construct'), $args);
}
public function query() {
$args = func_get_args();
// log it
if (isset($this->log)) {
$this->log->log("PDO query=[{$args[0]}]");
}
// pass through
return call_user_func_array(array (parent, 'query'), $args);
}
}
?>
http://bytejar.com/ - Software Lessons Learned the Hard Way
----
Server IP: 64.71.164.2
Probable Submitter: 24.148.133.105
----
Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php
Edit -- https://master.php.net/note/edit/77559
Del: integrated -- https://master.php.net/note/delete/77559/integrated
Del: useless -- https://master.php.net/note/delete/77559/useless
Del: bad code -- https://master.php.net/note/delete/77559/bad+code
Del: spam -- https://master.php.net/note/delete/77559/spam
Del: non-english -- https://master.php.net/note/delete/77559/non-english
Del: in docs -- https://master.php.net/note/delete/77559/in+docs
Del: other reasons-- https://master.php.net/note/delete/77559
Reject -- https://master.php.net/note/reject/77559
Search -- https://master.php.net/manage/user-notes.php