Bonjour,

J'ai un petit soucis d'héritage... Je n'ai pas énormément d'expérience en terme de POO mais là j'avoue que je ne comprends pas pourquoi ça ne fonctionne pas.

Voici l'exemple:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
class Foo {
	protected $foo;
	protected $tata = 'titi';
	public $bar;
 
	function _init() {
		$this->foo = 'toto';
		$this->bar = new Bar;
	}
}
 
class Bar extends Foo {
	public $baz;
	public $baz2;
 
	function __construct() {
		$this->baz = $this->foo;
		$this->baz2 = $this->tata;
	}
}
 
$foobar = new Foo;
$foobar->_init();
echo $foobar->bar->baz; // devrait retourner 'toto'
echo $foobar->bar->baz2; // retourne 'titi'
?>
Si quelqu'un peut m'expliquer pourquoi est-ce que j'arrive pas à acceder à la propriété $foo, cela me rendrait grandement service...
Elle prends bien la valeur qu'on lui assigne mais apparemment, l'héritage ne suit pas

Merci bien.