2017-02-28 80 views
-2

在這裏,我將我的代碼代碼運行在PHP 5.3.6,但不運行5.1.6

class1.php

<?php 
    class class1 
    { 
     public function test_class(){ 
      return "text_class"; 
     } 
    } 
?> 

class2.php

<?php 
    require_once "class1.php"; 
    class class2{ 
     public function __construct(){ 
       $this->classs=new class1(); 
     } 
     public function test_class2(){ 
      echo $this->classs->test_class(); 
      return "text_class"; 
      } 
     } 
?> 

運行class2.php時執行停止在class2.php contructor.no錯誤或警告不顯示。

我使用的PHP版本5.1.6

+0

使用錯誤報告http://php.net/manual/en/function.error-reporting.php如果您的系統沒有設置捕獲和默認顯示錯誤。 –

+0

我包括類error_reporting(E_ALL)但不工作的頂部 – sridhard

+0

請參閱下面給出的答案然後 –

回答

-1

在你的Class2文件,你應該定義屬性,那麼你可以在你的類的任意位置使用此屬性。

看看這個:

include_once "class1.php"; 
    class class2 
    { 
     private $classs; 

     public function __construct() 
     { 
       $this->classs = new class1(); 
     } 

     public function test_class2() 
     { 
      echo $this->classs->test_class(); 
      return "text_class2"; 
     } 
     } 

希望它會幫助你。

+0

工作很好,非常感謝。 – sridhard

相關問題