daGrevis Posted July 10, 2011 Report Posted July 10, 2011 Briedi, pats izlasīji? Es izlasīju visu, kas nav komentāri. Visam būtu jāstrādā, bet problēma - nestrādā kā vajadzētu. Uztaisi divus failus: foo1.php, foo2.php. Abos iemet "session_start()". Pirmajā uztaisi klasi ar divām metodēm (get_x(), set_x()) un mainīgo x. Tajā pašā pirmajā failā izsauc objektu, piešķir to mainīgajam foo. Tad ar metodi "uz'set'o" objekta mainīgo x. Uztaisi serialize() un jau serializēto mainīgo iemet sesijā. Otrā failā paņem attiecīgo sesijas mainīgo un uztaisi var_dump(). Es neredzēju attiecīgās metodes. Tikai mainīgo x. Quote
briedis Posted July 10, 2011 Report Posted July 10, 2011 Es neredzēju attiecīgās metodes. Tikai mainīgo x. ..nu bet kā tu iztēlojies, ka tur būs pats metožu kods? Jā, kā jau minēji, attiecīgajai klasei jābūt iekļautai. Šis man strādā: foo1.php <? session_start(); include 'FooBar.php'; $foobar = new FooBar; $foobar->setX(5); $_SESSION['foobar'] = serialize($foobar); var_dump($_SESSION['foobar']); var_dump($foobar); echo $foobar->getX(); foo2.php <? session_start(); include 'FooBar.php'; $foobar = unserialize($_SESSION['foobar']); var_dump($_SESSION['foobar']); var_dump($foobar); echo $foobar->getX(); FooBar.php <? class FooBar{ private $x; public function setX($x){ $this->x = $x; } public function getX(){ return $this->x; } } Quote
xPtv45z Posted July 10, 2011 Report Posted July 10, 2011 Vai tad šis jau visu nepasaka? Note that many built-in PHP objects cannot be serialized. However, those with this ability either implement the Serializable interface or the magic __sleep and __wakeup methods. If an internal class does not fulfill any of those requirements, it cannot reliably be serialized. Quote
briedis Posted July 10, 2011 Report Posted July 10, 2011 Vai tad šis jau visu nepasaka? If an internal class does not fulfill any of those requirements, it cannot reliably be serialized. Nu redzi, man veiksmīgi izdevās serializēt gan bez tā interfeisa, gan bez maģiskajām metodēm. Quote
daGrevis Posted July 11, 2011 Report Posted July 11, 2011 Note that many built-in PHP objects cannot be serialized. However, those with this ability either implement the Serializable interface or the magic __sleep and __wakeup methods. If an internal class does not fulfill any of those requirements, it cannot reliably be serialized. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.