Created
January 3, 2013 02:28
-
-
Save C-Duv/4440257 to your computer and use it in GitHub Desktop.
Reproduction code for ZF-12494 (http://framework.zend.com/issues/browse/ZF-12494):
A class implementing __wakeup() and a controller using it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 @) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment