2014-01-18 66 views
0

我有一個上傳文件腳本/var/www/u/repofolder。我想從不是來自文本$dir = ''的變量加載此鏈接。如何將變量用於公共靜態PHP?

<?php 
$path = "/var/www/u/"; 
$repo = "repofolder"; 
$all = $path.$repo; 

class gatorconf { 


public static function get($param) { 

    $config = array(


    'repository' => $all, instead 'repository' => '/var/www/u/repofolder', 

回答

0

它不可能像你想要的那樣做。請參閱Variable scopeStatic Keyword

注意:在您的情況下,變量$all不是靜態的。

你可以定義你喜歡的路徑:

$path = "/var/www/u/"; 
$repo = "repofolder"; 
define('PATH',$path.$repo); 

//.... 

$config = array('repository' => PATH); 
0

如果你只是想在你的gatorconf你可以只讓類變量可用

<?php 


class gatorconf { 

private $path = "/var/www/u/"; 
private $repo = "repofolder"; 
private $all = $path.$repo; 

public static function get($param) { 

    $config = array(


    'repository' => $this->all,