gevensen
asked on
Removing __PHP_Incomplete_Class Object
i am trying to run a report on a sunshop shopping cart table
the data is base 64 endoded and serialized
i get the following result after doing a base64decode and unserialize
__PHP_Incomplete_Class Object ( [__PHP_Incomplete_Class_Na me] => item [id] => 20 [quantity] => 1 [options] => Array ( ) [regid] => )
i am mainly looking for item id and quantitiy which is in there
my question is this
how do i remove the __PHP_Incomplete_Class Object error when i dont know the original class name
the code blow simply dumps the data on the screen and row[4] is the problem string
the data is base 64 endoded and serialized
i get the following result after doing a base64decode and unserialize
__PHP_Incomplete_Class Object ( [__PHP_Incomplete_Class_Na
i am mainly looking for item id and quantitiy which is in there
my question is this
how do i remove the __PHP_Incomplete_Class Object error when i dont know the original class name
the code blow simply dumps the data on the screen and row[4] is the problem string
while($row=mysql_fetch_array($result))
{
$return[] = $row;
echo(" OrderID - ");
print_r($row[1]);
echo(" ProductID - ");
print_r($row[2]);
echo(" Price - ");
print_r($row[3]);
echo(" Data Array - ");
$product_array = unserialize(base64_decode($row[4]));
echo nl2br("\n");
echo(" Trying to Unserialize ");
echo nl2br("\n");
print_r($product_array);
}
ASKER
the endcoed serialized value is here:
Tzo0OiJpdGVtIjo0OntzOjI6Im lkIjtpOjIw O3M6ODoicX VhbnRpdHki O2Q6MTtzOj c6Im9wdGlv bnMiO2E6MD p7fXM6NToi cmVnaWQiO3 M6MDoiIjt9
Tzo0OiJpdGVtIjo0OntzOjI6Im
ASKER
structure is text
OK. So decoded that becomes ...
O:4:"item":4:{s:2:"id";i:2 0;s:8:"qua ntity";d:1 ;s:7:"opti ons";a:0:{ }s:5:"regi d";s:0:""; }
And as you right point out ...
var_dump(unserialize(base6 4_decode(' ...')));
outputs ...
object(__PHP_Incomplete_Cl ass)#1 (5) {
["__PHP_Incomplete_Class_N ame"]=>
string(4) "item"
["id"]=>
int(20)
["quantity"]=>
float(1)
["options"]=>
array(0) {
}
["regid"]=>
string(0) ""
}
http://docs.php.net/unserialize shows you how this happens. The serialized data does contain the class info, so you can know where it came from.
You can use the unserialize_callback_func setting to help out here (see the snippet below).
At a complete minimum, the following additional PHP code will fix the problem ...
class item
{
}
With that uncommented, the output changes from ...
The class item needs to be available.
PHP Warning: unserialize(): Function mycallback() hasn't defined the class it was called for in C:\tun.php on line 16
object(__PHP_Incomplete_Cl ass)#1 (5) {
["__PHP_Incomplete_Class_N ame"]=>
string(4) "item"
["id"]=>
int(20)
["quantity"]=>
float(1)
["options"]=>
array(0) {
}
["regid"]=>
string(0) ""
}
to ...
object(item)#1 (4) {
["id"]=>
int(20)
["quantity"]=>
float(1)
["options"]=>
array(0) {
}
["regid"]=>
string(0) ""
}
O:4:"item":4:{s:2:"id";i:2
And as you right point out ...
var_dump(unserialize(base6
outputs ...
object(__PHP_Incomplete_Cl
["__PHP_Incomplete_Class_N
string(4) "item"
["id"]=>
int(20)
["quantity"]=>
float(1)
["options"]=>
array(0) {
}
["regid"]=>
string(0) ""
}
http://docs.php.net/unserialize shows you how this happens. The serialized data does contain the class info, so you can know where it came from.
You can use the unserialize_callback_func setting to help out here (see the snippet below).
At a complete minimum, the following additional PHP code will fix the problem ...
class item
{
}
With that uncommented, the output changes from ...
The class item needs to be available.
PHP Warning: unserialize(): Function mycallback() hasn't defined the class it was called for in C:\tun.php on line 16
object(__PHP_Incomplete_Cl
["__PHP_Incomplete_Class_N
string(4) "item"
["id"]=>
int(20)
["quantity"]=>
float(1)
["options"]=>
array(0) {
}
["regid"]=>
string(0) ""
}
to ...
object(item)#1 (4) {
["id"]=>
int(20)
["quantity"]=>
float(1)
["options"]=>
array(0) {
}
["regid"]=>
string(0) ""
}
<?php
ini_set('unserialize_callback_func', 'mycallback'); // set your callback_function
function mycallback($classname)
{
echo "The class $classname needs to be available.\n";
}
/* //uncomment to fix the problem
class item
{
}
*/
var_dump(unserialize(base64_decode('Tzo0OiJpdGVtIjo0OntzOjI6ImlkIjtpOjIwO3M6ODoicXVhbnRpdHkiO2Q6MTtzOjc6Im9wdGlvbnMiO2E6MDp7fXM6NToicmVnaWQiO3M6MDoiIjt9')));
In the callback, I would do use the $classname variable to require_once the appropriate class file.
function mycallback($classname)
{
require_once "classes_$classname.inc";
}
sort of thing.
function mycallback($classname)
{
require_once "classes_$classname.inc";
}
sort of thing.
ASKER
im still fairly new to php although i have done some c++ a few years back and i did see the unserialize tutorial in php.net but something is not clicking with me
i see the uncomment to fix but what do i declare my class item as and where do i put the
function mycallback($classname)
{
require_once "classes_$classname.inc";
}
btw i really do appreciate the help this one has been making me a little batty
i see the uncomment to fix but what do i declare my class item as and where do i put the
function mycallback($classname)
{
require_once "classes_$classname.inc";
}
btw i really do appreciate the help this one has been making me a little batty
<?php
ini_set('unserialize_callback_func', 'mycallback'); // set your callback_function
function mycallback($classname)
{
echo "The class $classname needs to be available.\n";
}
/* //uncomment to fix the problem
class item
{
}
*/
var_dump(unserialize(base64_decode('Tzo0OiJpdGVtIjo0OntzOjI6ImlkIjtpOjIwO3M6ODoicXVhbnRpdHkiO2Q6MTtzOjc6Im9wdGlvbnMiO2E6MDp7fXM6NToicmVnaWQiO3M6MDoiIjt9')));
I assume the class is already defined somewhere as it was serialized before putting it into the DB.
All I can say is that it is called item. The name of the file containing that ... I don't know.
What code wrote to the DB?
All I can say is that it is called item. The name of the file containing that ... I don't know.
What code wrote to the DB?
ASKER
thats the hard part
i cant get any info from sunshop, they refuse to answer any questions
and they dont have any good reports either
so im not sure where the class is declared
is there a way to create a phony class just to strip away the info i need?
i cant get any info from sunshop, they refuse to answer any questions
and they dont have any good reports either
so im not sure where the class is declared
is there a way to create a phony class just to strip away the info i need?
Yes ...
class info{}
If you look at comment 24044455, you will see the proof.
But having the class exist, you get an object which is class item with just the properties you've retrieved.
Do you not have access to the rest of the code?
class info{}
If you look at comment 24044455, you will see the proof.
But having the class exist, you get an object which is class item with just the properties you've retrieved.
Do you not have access to the rest of the code?
ASKER
ok im not as dense as i thought i found a way by googling some of the code you supplied there was a similar example on http://php.nusa.net.id/manual/en/function.unserialize.php
the unknown php object is gone
now i simply get 2 errors
any idea how to get rid of them?
Notice: Undefined variable: row in C:\wamp\www\phptesting\dat adump3.php on line 2
OrderID - 10001 Data Array -
item Object ( [id] => 20 [quantity] => 1 [options] => Array ( ) [regid] => )
OrderID - 10004 Data Array -
Fatal error: Cannot redeclare class item in C:\wamp\www\phptesting\dat adump3.php (13) : eval()'d code on line 1
the unknown php object is gone
now i simply get 2 errors
any idea how to get rid of them?
Notice: Undefined variable: row in C:\wamp\www\phptesting\dat
OrderID - 10001 Data Array -
item Object ( [id] => 20 [quantity] => 1 [options] => Array ( ) [regid] => )
OrderID - 10004 Data Array -
Fatal error: Cannot redeclare class item in C:\wamp\www\phptesting\dat
<?php
$serializedData=$row[4];
//declare the unknown object
class MyClass {}
$object = unserialize($serializedData);
//declare the unserialize function
function unserializeUnknownObject($text)
{
$matches = Array();
preg_match_all('/O:(\d)*:"([^":]*)":/', $text, $matches);
foreach ($matches[2] as $class)
{
eval('class '.$class.' { }');
}
return unserialize($text);
}
$object = unserializeUnknownObject($serializedData);
$abs_path = dirname(dirname(__FILE__));
include $abs_path.'\sunshop_reports\include\config.php';
// include $abs_path.'\phptesting\include\phperrorfunction.php';
// Connects to your Database
$connection=mysql_connect($servername, $dbusername, $dbpassword) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$sql_query=" SELECT * FROM `ss_orders_products` LIMIT 0 , 30";
$result=mysql_query($sql_query,$connection);
if (!$result)
{
die('Invalid query: ' . mysql_error());
}
$session_data = array();
while($row=mysql_fetch_array($result))
{
$return[] = $row;
echo(" OrderID - ");
print_r($row[1]);
echo(" Data Array - ");
$pulledata=($row[4]);
$session_data = base64_decode($row[4]);
$decodedtext=unserializeUnknownObject($session_data);
echo nl2br("\n");
echo nl2br("\n");
print_r($decodedtext);
echo nl2br("\n");
echo nl2br("\n");
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yer a genius that dumps all
i still get
Notice: Undefined variable: serializedData in C:\wamp\www\phptesting\inc lude\phper rorclass.p hp on line 3
Notice: Undefined variable: serializedData in C:\wamp\www\phptesting\inc lude\phper rorfunctio n.php on line 14
im assuming that comes from $serializedData in
class MyClass {}
$object = unserialize($serializedDat a);
any ideas on that before i close this out?
i still get
Notice: Undefined variable: serializedData in C:\wamp\www\phptesting\inc
Notice: Undefined variable: serializedData in C:\wamp\www\phptesting\inc
im assuming that comes from $serializedData in
class MyClass {}
$object = unserialize($serializedDat
any ideas on that before i close this out?
No idea what you are doing there.
Can you put up the all the code.
Can you put up the all the code.
ASKER
the errors come on the 1st 2 lines only saying $serializedData is an undefined variable
it then proceeds without error and prints all the class objects to the screen
this is just a step to debug it before i pull the object data and write it to a new table and join it in a sql query to create my desired report
the whole exercise here is to pull quan and item id out so i can write that and a few other simple items to a new table
the printing to the screen is just a visual thing for my benefit so i can see whats happening
it then proceeds without error and prints all the class objects to the screen
this is just a step to debug it before i pull the object data and write it to a new table and join it in a sql query to create my desired report
the whole exercise here is to pull quan and item id out so i can write that and a few other simple items to a new table
the printing to the screen is just a visual thing for my benefit so i can see whats happening
// the includes
// include_once 'include\phperrorclass.php';
<?php
class MyClass {}
$object = unserialize($serializedData);
?>
// include_once 'include\phperrorfunction.php';
<?php
function unserializeUnknownObject($text)
{
$matches = Array();
preg_match_all('/O:(\d)*:"([^":]*)":/', $text, $matches);
foreach ($matches[2] as $class)
{
if (!class_exists($class, False)) {
eval('class '.$class.' { }');
}
}
return unserialize($text);
}
$object = unserializeUnknownObject($serializedData);
?>
// the code that calls the function
<?php
//declare the unknown object
include_once 'include\phperrorclass.php';
include_once 'include\phperrorfunction.php';
//declare the unserialize function
$abs_path = dirname(dirname(__FILE__));
include $abs_path.'\sunshop_reports\include\config.php';
// include $abs_path.'\phptesting\include\phperrorfunction.php';
// Connects to your Database
$connection=mysql_connect($servername, $dbusername, $dbpassword) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$sql_query=" SELECT * FROM `ss_orders_products` LIMIT 0 , 30";
$result=mysql_query($sql_query,$connection);
if (!$result)
{
die('Invalid query: ' . mysql_error());
}
$session_data = array();
while($row=mysql_fetch_array($result))
{
$return[] = $row;
echo(" OrderID - ");
print_r($row[1]);
echo(" Data Array - ");
$pulledata=($row[4]);
$session_data = base64_decode($row[4]);
$decodedtext=unserializeUnknownObject($session_data);
echo nl2br("\n");
print_r($decodedtext);
echo nl2br("\n");
echo nl2br("\n");
}
?>
I'm not following your code.
Your initial code was working just fine.
Nearly.
Go back to my code and replace ...
function mycallback($classname)
{
echo "The class $classname needs to be available.\n";
}
with ...
function mycallback($class)
{
if (!class_exists($class, False))
{
eval('class '.$class.' { }');
}
}
Your initial code was working just fine.
Nearly.
Go back to my code and replace ...
function mycallback($classname)
{
echo "The class $classname needs to be available.\n";
}
with ...
function mycallback($class)
{
if (!class_exists($class, False))
{
eval('class '.$class.' { }');
}
}
If you echo it to your browser, copy and paste it from the view-source page, not the rendered output.