I created a simple Drupal module that uses a singleton simulation template to store data between call calls. However, this does not seem to be data storage, as I hope.
It's also a problem understanding PHP, not Drupal, but in case anyone has Drupal advice, here's what I do.
Singleton setup
class TempStore { private $_fileName; public function getFileName() { return $_fileName; } public function setFileName($fileName) { $_fileName = $fileName; } function __construct() { } } function MYMODULE_data() { static $data; if (!isset($data)) $data = new TempStore(); return $data; }
The problem is visible even within the same function.
function MYMODULE_file_insert($file) { $token = $file->timestamp; MYMODULE_data()->setFileName($token);
Error message
Note: Undefined variable: _fileName in TempStore-> getFileName ()
Since this happens in the same function call, I believe that this is a failure in my understanding of how PHP handles such things and is not related to Drupal.
Can anyone understand what is wrong?
source share