特征中非静态方法的链式静态方法

时间:2014-11-17 12:27:55

标签: php setter getter traits

我有这样的特质

namespace Files;

trait Upload {

   //  name of input form
   public $inputName;
   // directory that you chose to upload file
   public $directory;
   //uploaded file name
   public $filneName;
   public $fullUploadedAdress;
   //uploaded file extention
   public $ext;
   //uploaded file size
   public $fileSize;
   // errors
   public $error;

   public  function Input ( $inputName )
   {
          //RETURN NAME OF UPLOAD FORM INPUT
          $this->inputName = $inputName;
          return $this;
   }
}

和另一个类似的

namespace RequestResponse;

class SetAndGetMethod
{
   use \Files\Upload;

   static protected $uploadInputName;
   protected static $onlyInstance;

   function __construct () { }

   public static function __callStatic ( $methodName, $args )
   {
          if ( preg_match ( '~^(post|get|request|file)([a-z|A-Z])(.*)$~', $methodName, $matches ) ) {
                 $property = strtolower ( $matches[ 1 ] );
                 $inputName = $matches[ 2 ] . $matches[ 3 ];
                 if ( !method_exists ( __CLASS__, $property ) ) {
                        throw new \Exception( 'Property ' . $property . ' not exists' );
                 }
                 switch ( $matches[ 1 ] ) {
                        case 'post':
                               return self::post ( $inputName );
                        case 'get':
                               return self::get ( $inputName );
                        case 'request':
                               return self::request ( $inputName );
                        case 'file':
                               return self::request ( $inputName );
                        case 'default':
                               throw new \eimaException ( 'Method ' . $methodName . ' not exists' );
                 }
          }
   }


   protected static function getself ()
   {
          if ( static::$onlyInstance === null ) {
                 static::$onlyInstance = new self;
          }
          return static::$onlyInstance;
   }


   public static function file ( $property )
   {
           self::$uploadInputName = $property;
          new self;
   }

}

当我用setter调用我的fileUpload方法并将此方法链接到我的trit时我得到此错误

Input::fileUpload()->Input('Upload');
  

致命错误:在第27行的C:\ wamp \ www \ Framework \ protected \ controller \ Home_Controller.php中的非对象上调用成员函数Input()

0 个答案:

没有答案