Skip to Main Content
PHP 5 Kochbuch, Third Edition
book

PHP 5 Kochbuch, Third Edition

by David Sklar, Adam Trachtenberg, Carsten Lucke, Matthias Brusdeylins, Ulrich Speidel, Stephan Schmidt
September 2009
Intermediate to advanced content levelIntermediate to advanced
912 pages
48h 11m
German
O'Reilly Verlag
Content preview from PHP 5 Kochbuch, Third Edition

7.17 Zusammengesetzte Klassen verschmelzen

Problem

Sie möchten zwei oder mehr Klassen so zusammensetzen, dass sie sich wie eine einzige Klasse zu verhalten scheinen.

Lösung

Setzen Sie die Objekte zusammen und nutzen Sie die magische Methode __call( ), um Methodenaufrufe abzufangen und entsprechend weiterzuleiten:

class Adresse { protected $stadt; public function setStadt($stadt) { $this->stadt = $stadt; } public function getStadt() { return $this->stadt; } } class Person { protected $name; protected $adresse; public function __construct() { $this->adresse = new Adresse; } public function setName($name) { $this->name = $name; } public function getName() { return $this->name; } public function __call($methode, $argumente) { if (method_exists($this->adresse, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP programmieren unter Windows

PHP programmieren unter Windows

Arno Hollosi
CSS Kochbuch, 3rd Edition

CSS Kochbuch, 3rd Edition

Joergen Lang, Christopher Schmitt

Publisher Resources

ISBN: 9783868993271Purchase book