for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
class Snidel_Data
You can fix this by adding a namespace to your class:
namespace YourVendor; class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.
{
/** @var int */
private $pid;
/**
* @param int $pid
*/
public function __construct($pid)
$this->pid = $pid;
$this->shm = new Snidel_SharedMemory($pid);
shm
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
}
* write data
*
* @param mix $data
* @return void
* @throws RuntimeException
public function write($data)
$serializedData = serialize(array(
'pid' => $this->pid,
'data' => $data,
));
try {
$this->shm->open(strlen($serializedData));
} catch (RuntimeException $e) {
throw $e;
$this->shm->write($serializedData);
$this->shm->close();
* read data and delete shared memory
* @return mix
public function readAndDelete()
$data = $this->read();
$this->delete();
return $data;
* read data
* @return array
public function read()
$this->shm->open();
$data = $this->shm->read();
$unserialized = unserialize($data);
return $unserialized['data'];
* delete shared memory
public function delete()
return;
$this->shm->delete();
$this->shm->close($removeTmpFile = true);
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.