gamex Posted May 25, 2010 Share Posted May 25, 2010 I am having this issue that is driving me insane. To make things worse, I tried creating a small, test script for this post so you guys could get a feel as to how I had things set up, but my little test script works the way I expect my main script to work. The problem I am having is that I have protected variables in my class that I am trying to save to a session. For some reason, they will not. If I change them to public, it works fine. This is the test code I made to give you an idea on how my classes are set up: abstract class GeneralCart { protected $other_var = true; protected $items = array(); public function __sleep(){ return array("items"); } public function addItem($item){ $this->items[] = $item; } public function getItems(){ return $this->items; } } class Cart extends GeneralCart { // Other stuff in here } class Customer { public $cart; public function __construct(){ $this->cart = new Cart(); } } $test = new Customer(); $test->cart->addItem("ItemA"); print_r(serialize($test)); Has anyone ever run into this issue before? I actually just did a var_dump of my actual class, and I noticed something weird: ["items:protected"]=> array(0) { } But then if you scroll down a little bit ["items"]=> array(3) { // All items are here } Any ideas whats going on? Quote Link to comment Share on other sites More sharing options...
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.