I get the error below. Now I could set $good_ucase_numbers, $good_lcase_numbers to be static and use self:: in the constructor OR I could put them as arguments in the constructor and send them when instantiated. But I want to know why this will not work. I should be able to merge the 2 arrays in the constructor using $this-> 😕

Fatal error: Access to undeclared static property: Captcha::$good_ucase in C:\blah\Captcha.php on line 39

class Captcha {
	public $length;

private $captcha;

protected $good_ucase = array('A', 'B', 'C');
protected $good_lcase = array('a', 'b', 'c');
protected $good_numbers = array(1, 2, 3);
protected $good_ucase_numbers, $good_lcase_numbers;
protected $font_path = '.fonts/';
protected $ucase_fonts = array('a.ttf', 'b.ttf', 'c.ttf');
protected $lcase_fonts = array('a.ttf', 'b.ttf');

public function __construct()
{
	$this->$good_ucase_numbers = array_merge($this->$good_ucase, $this->$good_numbers);//ERROR HERE
	$this->$good_lcase_numbers = array_merge($this->$good_lcase, $this->$good_numbers);
	$this->$captcha = $this->create_captcha();
}
}

$captcha = new Captcha();

    The error message seems wrong to me. I'd have expected undefined variable $good_ucase. You want $this->good_ucase, not $this->$good_ucase.

      Write a Reply...