<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> parent2.php </title>
<meta charset="UTF-8">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<?php
class A {
var $a="hello I am A<br>";
function example() {
echo "I am A::example()<br />";
echo $this->a;
}
}
class B extends A {
function example() {
echo "I am B::example()<br />";
parent::example();
}
}
$b = new B;
// 这将调用 B::example(),而它会去调用 A::example()。
$b->example();
echo '<hr>';
//B::example();
?>
<hr><hr><hr>
<?php
class AA {
var $a="hello I am AA<br>";
function example() {
echo "I am AA::example()<br />";
echo $this->a;
}
}
class BB extends AA {
function example() {
echo "I am BB::example()<br />";
AA::example();
}
}
$b = new BB;
// 这将调用 B::example(),而它会去调用 A::example()。
$b->example();
echo '<hr>';
BB::example();
?>
</body>
</html>
I am B::example()
I am A::example()
hello I am A
I am BB::example()
I am AA::example()
hello I am AA
I am BB::example()
I am AA::example()
( ! ) Fatal error: Using $this when not in object context in D:\LearnWebDevelop\php\MyPhpExse\parent2.php on line 40 | ||||
---|---|---|---|---|
Call Stack | ||||
# | Time | Memory | Function | Location |
1 | 0.0019 | 379328 | {main}( ) | ..\parent2.php:0 |
2 | 0.0019 | 379728 | BB::example( ) | ..\parent2.php:55 |
3 | 0.0019 | 379728 | AA::example( ) | ..\parent2.php:47 |