0

我有以下代码:

<?php

class picture{

private $path = 'files/';
private $login = base64_decode('dGVzdGluZw==');
private $password = base64_decode('MTIzNDU2');
private $image_path = $this->path.time().'.jpg';

//code

我收到以下错误:

解析错误:解析错误,在第 6 行的*','' or中期待';''

第 6 行$path是声明的行。

4

2 回答 2

2

您不能直接将函数的返回值分配给 PHP 中的成员声明。改用构造函数:

<?php

class picture {

  private $path = 'files/';
  private $login;
  private $password;
  private $image_path;

  public function __construct() {
    $this->login = base64_decode('dGVzdGluZw==');
    $this->password = base64_decode('MTIzNDU2');
    $this->image_path = $this->path.time().'.jpg';
  }

}
?>
于 2012-07-31T19:24:47.687 回答
2

设置属性时您无权访问变量“路径”

将此信息添加到您的构造函数是一种很好的做法

class picture {

   private $path;
   private $login;
   private $password;
   private $image_path;

   function __construct() {
      $this->path = 'files/';
      $this->login = base64_decode('dGVzdGluZw==');
      $this->password = base64_decode('MTIzNDU2');
      $this->image_path = $this->path.time().'.jpg';
   }
}
于 2012-07-31T19:25:32.890 回答