I am using PHP 5.3.8 with CakePHP 2.1.1.
This is my view (the layout is empty, actually it only outputs the view itself)
<?php
// $present is not a view variable
$present = 'Hello World!';
class ApplicationsPDF
{
public function CreateApplicationTable()
{
global $present;
exit(var_dump($present));
}
}
$pdf = new ApplicationsPDF();
$pdf->CreateApplicationTable();
?>
The output is null instead of “Hello World!”.
If I copy and paste this code into a single file (which I directly run from the browser), it perfectly works!
So it must be a CakePHP bug. Does anyone know it?
It’s not a PHP nor a CakePHP bug!
It’s because CakePHP includes the view in its view class so the declared variables aren’t really in the global scope and
globalhas no effect.From ADmad (source):