Fatal error: Using $this when not in object context in parent2.php

346 篇文章 0 订阅

<!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
#TimeMemoryFunctionLocation
10.0019379328{main}( )..\parent2.php:0
20.0019379728BB::example( )..\parent2.php:55
30.0019379728AA::example( )..\parent2.php:47


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值