0

I have the following code:

<?php

class picture{

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

//code

I get the following error:

Parse error: parse error, expecting ','' or';'' in * on line 6

Line 6 is the line on which $path is declared.

1

2 Answers 2

2

You cannot directly assign the return value of a function to a member declaration in PHP. Use a constructor instead:

<?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';
  }

}
?>
Sign up to request clarification or add additional context in comments.

Comments

2

You don't have access to the variable 'path' when setting properties

It is good practice to add this information to your constructor

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';
   }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.