note 29987 deleted from ref.objaggregation by didou
| From: | didou@php.net | Date: | Thu, 03 Jul 2003 10:02:13 +0000 |
| Subject: | note 29987 deleted from ref.objaggregation by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-51413@lists.php.net to get a copy of this message | ||
Note Submitter: galland@appli-box.com
----
Bug free example on class association
<?php
/**
* corrected example of
*http://www.php.net/manual/en/ref.objaggregation.php
* two errors corrected =
* 1 = declaration of $_dt
* 2 $dateTime = $_dt->now(); in generateReport ($_dt is nothing !)
**/
class DateTime {
function DateTime() {
// empty constructor
}
function now() {
return date("Y-m-d H:i:s");
}
}
class Report {
/**
* example is false here : http://www.php.net/manual/en/language.oop.php#keyword.class
* so we make instanciation in constructor
*/
//var $_dt = new DateTime();
var $_dt;
// more properties ...
function Report() {
//association
$this->_dt = new DateTime();
// initialization code ...
}
function generateReport() {
//example is false here
//$dateTime = $_dt->now();
$dateTime = $this->_dt->now();
// more code ...
return $dateTime;
}
// more methods ...
}
$rep = new Report();
echo '<pre>';
var_dump($rep);
echo '</pre>';
echo $rep->generateReport();
?>