GET 500 (Internal error) PHP

Asked

Viewed 262 times

1

Good morning,

I wrote a PHP class

<?php 

private $v;
private $v2;
private $v3;

public function __construct(){
    printf("Objeto criado com sucesso!");
}

public function setValor(){
    $this->$v = "valor";
    $this->$v2 = "valor2";
    $this->$v3 = "valor3";
}

public function getValor1(){
    return $this->$v;
}

public function getValor2(){
    return $this->$v2;
}

public function getValor3(){
    return $this->$v3;
}
}
$t = new Teste();
$t->setValor();
?>

But I can’t access serValor() method, I always get GET 500 error (Internal Server Error), however I don’t see anything wrong in the code, someone can help?

  • I find it strange to be only in this method: experiment: $this->v = "valor"; without the "$" at all

1 answer

2


When accessing variables, you no longer need to use the dollar sign $.

public function setValor(){
    $this->v = "valor";
    $this->v2 = "valor2";
    $this->v3 = "valor3";
}
  • Thanks, I solved XD!

  • 2

    Reverti to issue 3, because it’s neither what the author of the question accepted nor Henry’s intention. If someone has an answer other than the current one, just post separately (and you are welcome to collaborate, after all the format of the site is a question and several answers, and this is encouraged). If the new answer is better, the questioner may change the acceptance at any time. Taking advantage of someone else’s CCEPT opens up doubtful precedents, however good the intention is and prevents the community from voting separately on each employee.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.