2013-06-12 23 views

回答

0
// myfile.php 

include('../config.php'); 

class frontproduct { 

    function fetchrange(){ 


    } 

} 

您应该包括类代码之前的配置文件,请确保你了解你应该如何使用相对路径。

0

试试这个

class frontproduct{ 

function fetchrange(){ 
ob_start(); 
    include('..config.php'); 

$val = ob_get_clean(); 
return $val; 
    } 
} 
4

这里是在最好以最坏的做法

列表

1:包括并通过构造函数注入类

include("config.inc.php"); 

$fp = new frontproduct($config); 

2:包括并通过setter方法注入(“可选依赖性”方法)

include("config.inc.php"); 

$fp = new frontproduct(); 
$fp->setConfig($config); 

3:通入函数调用(即 “不应该对象更容易” 的方法)

include("config.inc.php"); 

$fp = new frontproduct(); 
$fp->doSomething($config, $arg); 
$fp->doSomethingElse($config, $arg1, $arg2); 

4:进口类(又名 “沉默的依赖性方法”)

class frontproduct{ 
    public function __construct(){ 
     include('config.inc.php'); 
     $this->config = $config; 
    } 
}  

5:静态属性赋值(又名“至少它不是一个全球性的”方法)

include ("config.inc.php"); 
frontproduct::setConfig($config); 

6:全球分配(又名“是什么范围”的方法)

include ("config.inc.php"); 
class frontproduct{ 
    public function doSomething(){ 

     global $config; 
     } 
    } 
相关问题