Undefined variable error with protected variable (solved)


Hi Folks, the variable $_monthNumber is defined protected in the class und used in the functions initialize and guvpdf.
I get the error: undefined variable in guvpdf, bute why??
As I understood protected variables are visible in the same class. I have used it with $this and without-

class JournalsController extends AppController {

protected $array;
protected $product;
protected $_monthNumber;

public function initialize() {
    $this->set('menuID', 'accounts');
    $this->set('product', 'product3');
    $timestamp = time();
    $_monthNumber = date("n", $timestamp);


public function guvpdf() {
$actYear = Configure::read(‘actualYear’);
$months = Configure::read(‘Months’);
$orient = ‘portrait’;
$this->set(‘month_number’, $this->$_monthNumber);
$this->set(‘month_names’, $months);


$this->set(‘month_number’, $this->_monthNumber);


Hi, thanks this is helping to avoid the error, and I never read about removing the leading $-sign.
Now the error is gone, but the variable is empty. In the ‘initialize’ the value is available but not in another function of the same class. Do you know why?


should be

$this->_monthNumber = date("n", $timestamp);



Thanks, with some more readings and your advice now I understand the system and can apply it throughout the application.