Welcome Guest Search | Active Topics | Members | Log In | Register

Serializing Private Variables Options · View
spydermonkey
Posted: Thursday, May 15, 2008 1:38:17 PM
Rank: Newbie Coder
Groups: Member

Joined: 4/28/2008
Posts: 6
Points: 0
Has anyone successfully serialized private variables in PHP with private variables in Flex?
Here is what I am talking about.

PHP Object

class foo{
private $_name = "";

public function getName(){return $this->_name;}
public function setName($val){$this->_name = $val;}
}

AS object
[Bindable]
[RemoteObject(alias="model.foo")]
public class foo{
private var $_name:String = "";

public function get name():String{return this._name;}
public function set name(val:String){this._name = val;}

}

when i make a remote service call the objects are of the correct type but the values for the attributes are blank. now if i make all the fields on the php side public and remove the _ (ie. public var $name) then the values are there.

has anyone else ran into this problem? I have used this type of approach before in ColdFusion but I on the CF object side you must specify all the fields in tags, and i think that is how it knows to match up the correct fields.

my options seem to be, make public variables on the PHP side, well i dont really want to do that.
or figure out how to make this work. i should be able to have private variables on both the flex and php side.
spydermonkey
Posted: Thursday, May 15, 2008 2:07:54 PM
Rank: Newbie Coder
Groups: Member

Joined: 4/28/2008
Posts: 6
Points: 0
Another thought is create a DataTransitionObject DTO that will have all public fields for the objects that I am going to send over the wire. This has two sides though, annoying b/c i have to create another object for each one that i will be sending accross the line and i have to get and set each property in the DTO. But it would work and allow me to keep all the properties in my objects to be private. Of course there would also be the extra function call to map the data from the value objects (private variables) to the DTO's (public variables).

any thoughts?
Valdhor
Posted: Monday, June 02, 2008 8:33:45 AM
Rank: Newbie Coder
Groups: Member

Joined: 3/19/2008
Posts: 11
Points: 12
Location: USA
I don't believe you quite understand the way PHP can overload its members.

This is how I would do it in PHP5:

class foo{
private $name = "";

public function __get(){return $this->name;}
public function __set($val){$this->name = $val;}
}

$myFoo = new foo();
$myFoo->name = "My Name";
echo $myFoo->name;

If there are multiple members you need to use an array.

For more details check out http://us.php.net/manual/en/language.oop5.overloading.php

Disclaimer: I have not tried this technique with remote objects in Flex.
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFVision Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v4.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.
This page was generated in 0.082 seconds.