public
Created

Reproduction code for ZF-12494 (http://framework.zend.com/issues/browse/ZF-12494): A class implementing __wakeup() and a controller using it.

  • Download Gist
IndexController.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
<?php
 
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
switch ($this->_getParam('what', 'test')) {
case 'store': $this->_store(); break;
case 'retrieve': $this->_retrieve(); break;
case 'clear': $this->_clear(); break;
case 'test':
default: $this->_test(); break;
}
echo '<hr />';
echo '<a href="' .$this->_helper->url->url(array('controller' => 'index', 'action' => 'index', 'what' => 'test')) . '">Test object (no session)</a> | ';
echo '<a href="' .$this->_helper->url->url(array('controller' => 'index', 'action' => 'index', 'what' => 'store')) . '">Store (Note: clear before storing again)</a> | ';
echo '<a href="' .$this->_helper->url->url(array('controller' => 'index', 'action' => 'index', 'what' => 'retrieve')) . '">Retrieve</a> | ';
echo '<a href="' .$this->_helper->url->url(array('controller' => 'index', 'action' => 'index', 'what' => 'clear')) . '">Clear</a>';
}
protected function _getSubject()
{
$s = new Application_Model_SleepingModel();
$s->aMember = 'foo';
$s->anotherMember = 'bar';
return $s;
}
protected function _test()
{
$subject = $this->_getSubject();
echo 'My test subject:';
var_dump($subject);
echo 'Serialize:';
$subject_ser = serialize($subject);
var_dump($subject_ser);
echo 'Wake-up :';
$o2 = unserialize($subject_ser);
var_dump($o2);
}
protected function _store()
{
echo '(please clear before storing again)<br />';
$subject = $this->_getSubject();
$subject->anotherMember = 'baz';
echo 'My test subject:';
var_dump($subject);
echo 'Storing in session...';
$session = new Zend_Session_Namespace('testingSleepingModel');
$session->mySleeper = $subject;
echo '... done';
}
protected function _retrieve()
{
echo 'Fetching from session...';
$session = new Zend_Session_Namespace('testingSleepingModel');
var_dump($session->mySleeper);
echo '... done';
}
protected function _clear()
{
@Zend_Session::destroy(true, false);
}
}
SleepingModel.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13
<?php
 
class Application_Model_SleepingModel
{
public $aMember;
public $anotherMember;
public function __wakeup()
{
$arr = array();
$foo = @$arr['bar']; // Try to use some index that doesn't exists (but silence the error with @)
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.