Solved

Flash to PHP serielize error.

Posted on 2004-04-13
30
948 Views
Last Modified: 2008-03-03
Hi

I'm trying to send serialized variables from Flash to PHP, my trouble is that I get a __PHP_Incomplete_Class Object and __PHP_Incomplete_Class_Name] => object errors and I'm unable to access the data in the Object. According to the PHP man's there should be multiple ways of correcting, though I've unsuccesfuld in deploying them. It is said that I should include the which create the object when I  try to unserialize the data, but that class is made in Flash. I've tried to set up similar classes to that Flash used, but without succes.

this php:
print_r(unserialize(utf8_decode(urldecode($_POST['customerInfo']))));

outputs this:

__PHP_Incomplete_Class Object
(
    [__PHP_Incomplete_Class_Name] => object
    [Phone_work] => 123123123
    [Phone] => 123123123123
    [Email] => asd@asd.dk
    [AreaCode] => 1111
    [CoAddress] =>
    [Address] => asd
    [SurName] => asd
    [Name] => asd
    [Amount] => 77.15
    [Payment] => PostExchange
    [Delivery] => ParcelPost
)

So I'm supposed to include the class, that created that object? How da f*** do I that? Or is there a workaround?
0
Comment
Question by:seebach
  • 16
  • 6
  • 6
30 Comments
 
LVL 9

Expert Comment

by:techtonik
ID: 10812088
According to example from manual on http://php.net/unserialize
You can try to get a class name from callback function and then make a definition of the class with that name.

<?php
// unserialize_callback_func directive available as of PHP 4.2.0
ini_set('unserialize_callback_func','mycallback'); // set your callback_function

function mycallback($classname) {
   // just include a file containing your classdefinition
   // you get $classname to figure out which classdefinition is required
   echo $classname;
}
?>

print_r(unserialize(utf8_decode(urldecode($_POST['customerInfo']))));

I don't have flash tools to experiment, so you need to test this by yourself and if it will not work - please, post all data you consider may be useful to find a solution.
0
 
LVL 14

Expert Comment

by:ThG
ID: 10812142
You don't have to urldecode() because it's done automatically in the GET/POST HTTP process. You just need to correctly urlencode() when passing the parameter customerInfo.
0
 

Author Comment

by:seebach
ID: 10812609
/* partial content removed by ThG, EE Page Editor - it was just confusing (see following comment) */
0
 

Author Comment

by:seebach
ID: 10812640
Ignore the above (hittet enter by error!)

Hi techtonik

I've read the documentation for this like 100 times, I've also tested a lot of different ideas, on how that class should look.

if you look at the function in the callback class

function mycallback($classname) {

**** What should I WRITE here

   echo $classname;

The class comes from flash, I dont really now what it looks like! Ive tried to initiate the var again, but with no succes!
0
 

Author Comment

by:seebach
ID: 10812701
Hi ThG

If I remove the urldecode I get this error:

Notice:  unserialize(): Error at offset 0 of 568 bytes in /home/web/gb6324/wshop/admin/input.php on line 57

Believe me I had a lot of trouble figurering this out, since i took it for granted aswell!
0
 
LVL 9

Expert Comment

by:techtonik
ID: 10813180
What is class name? - contents of $classname ?
0
 

Author Comment

by:seebach
ID: 10813253
its 'customerInfo' but its origin is flash, so $classname does'nt exist, if could rename the object to like so

customerInfo
(
    customerInfo => object
    [Phone_work] => 123123123
    [Phone] => 1231....
)
ill be home free.
But you see it just says Incomplete all the time!

I've tried to create class's called 'customerInfo' based on a fake class.
$customerInfo = new customerInfo(); but with no succes :(

I feel I either missed something obscure, or got it completly wrong!
0
 
LVL 9

Expert Comment

by:techtonik
ID: 10815824
http://www.macromedia.com/devnet/mx/flash/articles/flmxpro_webservices_06.html

When you send data back and forth between Flash and PHP, you can lose complex data such as arrays or objects. The Serializer class lets you serialize and unserialize complex data, so you can retain its structure between Flash and PHP, and vice versa.
http://www.sephiroth.it/test/unserializer/

Project has moved to SourceForge.net
http://sourceforge.net/projects/serializerclass/

Serializer Class enable (For Macromedia Flash) you to pass and receive complex data type from and to PHP and Flash using the native PHP functions serialize and unserialize. Flash received data will be a native Flash object

----
That is just exactly what you need. =)
0
 

Author Comment

by:seebach
ID: 10816743
Yes, I've already looked into that (were are actually using most of this in the flash part), the trouble here is that it only the flash part! I am still looking for the PHP, the dokumentation also only shows some very simple back and forth passing of data. Otherwise its does look great! Only sad the PHP is so poorly dokumented!
0
 

Author Comment

by:seebach
ID: 10816971
this is what in the serializer class from sephiroth uses to unserialize:

$flashvars = $_POST['flashvar'];
if(get_magic_quotes_gpc()){
    $flashvars = stripslashes($flashvars);
}
// echo the result
var_dump (unserialize(urldecode($flashvars)));

http://cvs.sourceforge.net/viewcvs.py/*checkout*/serializerclass/examples/receiver.php?rev=1.1

not much different from mine, no re-intialisation or callback func :/
0
 
LVL 14

Expert Comment

by:ThG
ID: 10818540
Just a guess. Why do you need an object? can't you just access the data you want from raw array?

$x = unserialize(urldecode($flashvars));
print "Email is:" . $x['Email'];

Anyway it would be helpful if you can post the raw var_dump($_POST['customerInfo']), or even better, var_dump($_POST)
0
 

Author Comment

by:seebach
ID: 10821125
The raw dump looks like this:

/* object data removed by ThG (wasn't really needed anyway needed) */

I hope this tells you why I can't access the data without unserilizing it first ;)

The unserilize turns that into an object, if I somehow come make it into an array i would great!
0
 

Author Comment

by:seebach
ID: 10821181
If I try to access the data directly I get this error

echo $customerInfo->Email;

Notice:  main(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition <b>object</b> of the object you are trying to operate on was loaded _before_ the session was started in /home/web/gb6324/wshop/admin/input.php on line 62

Since its an object, and not an array I can't access it through:

$customerInfo['Email'];

the above is not eligeble for objects
0
 

Author Comment

by:seebach
ID: 10822582
SOLUTION!

Hey! Guys I've discovered the Answer!

The trouble seems to be the name of the object passed from flash!
It set as simply "object" the callback functions I created to deal with that won't work with that name!
so using this hacked script (attention to line 4):

<?
$customerInfo = $_POST['customerInfo'];

$customerInfo = preg_replace("/object/U", "custom", $customerInfo); // the hack!!!

function guess_class_name($classname){
      print "$classname";
      class custom{
            var $Phone_work;
            var $Phone;
            var $Email;
            var $AreaCode;
            var $CoAddress;
            var $Address;
            var $SurName;
            var $Name;
            var $Amount;
            var $Payment;
            var $Delivery;
      
      function custom(){
            }
      }
}
ini_set('unserialize_callback_func', 'guess_class_name');
 
$customerInfo = unserialize(utf8_decode(urldecode($customerInfo)));

?> <pre>  <?
// var_dump($_REQUEST);
echo "<br>customerInfo<br>";
print_r($customerInfo);
echo "<br>Email<br>";
echo $customerInfo->Email;
echo "<br>customerOrder<br>";

?> </pre>

this then outputs:
customerInfo
custom Object
(
    [Phone_work] => 123123123
    [Phone] => 123123123123
    [Email] => asd@asd.dk
    [AreaCode] => 1111
    [CoAddress] =>
    [Address] => asd
    [SurName] => asd
    [Name] => asd
    [Amount] => 1557.15
    [Payment] => PostExchange
    [Delivery] => PostOffice
)

Email
asd@asd.dk
customerOrder
O%3A6%3A%22object%22%3A11%3A%7Bs%3A10%3A%22Phone%5Fwork%22%
3Bs%3A9%3A%22123123123%22%3Bs%3A5%3A%22Phone%22%3Bs%3A12%3A
%22123123123123%22%3Bs%3A5%3A%22Email%22%3Bs%3A10%3A%22asd%4
0asd%2Edk%22%3Bs%3A8%3A%22AreaCode%22%3Bs%3A4%3A%221111%22%
3Bs%3A9%3A%22CoAddress%22%3Bs%3A0%3A%22%22%3Bs%3A7%3A%22Ad
dress%22%3Bs%3A3%3A%22asd%22%3Bs%3A7%3A%22SurName%22%3Bs%3A
3%3A%22asd%22%3Bs%3A4%3A%22Name%22%3Bs%3A3%3A%22asd%22%3B
s%3A6%3A%22Amount%22%3Bs%3A7%3A%221557%2E15%22%3Bs%3A7%3A%
22Payment%22%3Bs%3A12%3A%22PostExchange%22%3Bs%3A8%3A%22Delivery
%22%3Bs%3A10%3A%22PostOffice%22%3B%7D
the info

and everything is fine :) :) :)

So for everyone having the same error, check the NAME of your obejct! If you as I am not the author of the flash file,
try to use a replace funkction to get the name right!

VERY important! I changed the object named "object" to be the be named "custom" - notice there both 6 characters
- the new name most be the same number of letters as the original!

If someone knows exactly whats up with objects named "object" and php I really like to know!!!

Hope this helpes someone some day! Even this rightnow seems like an obscure coincedence of bad names!
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 14

Expert Comment

by:ThG
ID: 10825987
Sorry but I don't think you should request a refund for this question. I think we anyway helped in finding the correct solution, so you should accept one or more comments with "B" grade, as stated here:
http://www.experts-exchange.com/help.jsp#hi73
0
 

Author Comment

by:seebach
ID: 10826159
I don't really care about them points, if you think you deserve them keep them. But you can't diny being far of the solution since none of you ever worked on something using the same techniques! Also everything you suggested, I've already tried (which I stated in my first entry), and repeated a few times a long. Also I find the solution I've found was very unique, and until now not dokumented anywere (Believe me I've read everything).

But thanks for trying, believe me, I do appreciate it!

Im also gonna post the solution at PHP.net were it belongs :)

No offence ThG, but I was a bit wowed by you asking to use an array, maybe you should read up on
http://php.net/manual/en/language.oop.php in that sense i'm not sure a C would be justified!
0
 

Author Comment

by:seebach
ID: 10826187
Lunchy - just give them the points, its alright with me!

The solution and more - have been submitted!
0
 
LVL 9

Expert Comment

by:techtonik
ID: 10826388
I think this hack is a bad idea. For instance if serialized data contains strings like "object", and though this can be avoided by providing binary offset - it is not guaranteed to work with all flash versions.

Another question:
What if you have some methods defined in this object - how these will be unserialized? Probably they won't. =)

The answer is that flash and PHP objects are not compatible and can't be equally converted.. so you need a method to exchange data between PHP and flash objects. In another words - you will not get anything new trying to pass object from flash to PHP instead of passing simple array of data.

(I wonder if flash has associative arrays in language structure?)
0
 
LVL 9

Expert Comment

by:techtonik
ID: 10826426
You guys are too fast for my old bones.. =)
Can you supply your solution, plz.? I hope it is not too proprietary? =)

I'd really like to switch to flash from html soon, so this solution can be of help.
0
 

Author Comment

by:seebach
ID: 10826570
Hi Techtonik!

The Hack is a tempory solution, since I'm not the author of the flash! But the error lays in the Flash, the naming of objects in flash should be different.

The thing with the objects is that open serialization the methods are lost! Serialized data is very compact, 33% in size compared to xml. We might just have posted some data from flash to php, but due to the potentiel size we choose to serialize it, this saved af lot of bandwith. You can wddx and other methods which are easy'er to use, but not as compact as serialization!

(I wonder if flash has associative arrays in language structure?) YES! and complete OOB support, its very powerfull
0
 
LVL 14

Expert Comment

by:ThG
ID: 10826642
seebach, You are right, I was fooled by your print_r(), which i thought was suitable only for associative arrays, as I use var_dump() for all other variables. Forget that. :-)

Anyway it's not me that has to read the PHP manual, but you.

http://it2.php.net/manual/en/language.oop.serialization.php states:

"In order to be able to unserialize() an object, the class of that object needs to be defined."

Otherwise you get the above __PHP_Incomplete_Class:

<?php
$s = 'O:5:"dummy":1:{s:4:"data";s:2:"15";}';
print_r(unserialize($s));
?>

__PHP_Incomplete_Class Object
(
    [__PHP_Incomplete_Class_Name] => dummy
    [data] => 15
)
0
 

Author Comment

by:seebach
ID: 10826699
YES! I know that, I've tried that 1000 times with no preveil, I ended up figuring that it was me making errors. Until I was found that the Object was named "object" which for some reason won't  work in PHP! When I found that, my callback action worked!

I've written al this XXX times by now!
0
 
LVL 9

Expert Comment

by:techtonik
ID: 10826793
You can also think about implementing your own gateway which would compress data using GZ ZLIB algorithm - Flash should have some compressing functions. Given object this gateway can? enumerate all public properties, serialize, compress them, add a tagname and send to PHP. Upon receiving exactly the same data from PHP, gateway could? recreate object with given properties.

This way you can also choose only necessary object fields to pass to/from PHP.
0
 
LVL 14

Accepted Solution

by:
ThG earned 125 total points
ID: 10826879
seebach, why is that? As demonstrated in the following example, it doesn't matter how the object was named. If the object was named "alexander", it would generate an incomplete object anyway. You just have to declare the class first, as you found out by yourself. It doesn't matter how it is called.

<?php
class object { var $data1, $data2; }

$s = 'O:6:"object":2:{s:5:"data1";s:2:"15";s:5:"data2";s:2:"44";}';

print_r(unserialize($s));
?>

object Object
(
    [data1] => 15
    [data2] => 44
)
0
 

Author Comment

by:seebach
ID: 10826930
When I run the script locally, with a $s = 'O:6:"object":2:{s:5:"data1";s:2:"15";s:5:"data2";s:2:"44";}'; or so - it works fine!

Its only when the data is posted, and named object, it goes wrong!
0
 

Author Comment

by:seebach
ID: 10826979
WOW, Ill take it all back! That does work!

Thanks so much!

Just a sec I'll do a fullscale test!
0
 

Author Comment

by:seebach
ID: 10827046
Okay, Ill take back what I said, and gonna buy some more books on PHP aND OOP - though my solution works - you solved the problem!!!

Thanks again! If you ever come to Århus Denmark - you'll have some wery good Chocolat Beer and Banana split coming your way!

Cheers! One happy Seebach

guess you neded a push ;)
0
 
LVL 14

Expert Comment

by:ThG
ID: 10829254
hehe i didn't understand what was your problem in the end, but i'm pleased i explained myself.

regards
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now