Forcing Access to _Php_Incomplete_Class Object Properties

forcing access to __PHP_Incomplete_Class object properties

This issue appends when you un serialize an object of a class that hasn't been included yet.
For exemple, if you call session_start before include the class.

A PHPIncompleteClass object can't be accessed directly, but it's ok with foreach, serialize and gettype.
Calling is_object with an PHPIncompleteClass object will result false.

So, if you find a '__PHP_Incomplete_Class' object in your session and you've included your class after the session_load, you can use this function :

function fixObject (&$object)
{
if (!is_object ($object) && gettype ($object) == 'object')
return ($object = unserialize (serialize ($object)));
return $object;
}

This will results a usable object :

fixObject($_SESSION['member']);

How to get the class name out of an incomplete class?

Based on a suggestion to look at

forcing access to __PHP_Incomplete_Class object properties

The property can be accessed via foreach and ArrayObject

<?php

$array = new \ArrayObject($object);
var_dump($array['__PHP_Incomplete_Class_Name']);

__PHP_Incomplete_Class_Name wrong

Hakre's suggestion to look at session_write_close led me to what appears to be a reliable fix:

register_shutdown_function('session_write_close');

This forces the session to be written out before any memory cleanup and class unloading occurs. This is important due to a change in PHP that can result in a race condition between APC removing class references and PHP writing out the session data: http://news.php.net/php.internals/46999

How to allow only authorised clients to access object properties

It strikes me as a bad design in this case. You'd violate the single-responsibility principle of the class. Instead, refactor your code into more than one class, but use composition to attach optional properties.

For example:

class MyDataObject {
private $main_property;
private $extended_property;

/* ... getters/setters for $main_property. */
public function set_extended_property(IExtendedProperty $property) {
$this->extended_property = $property;
}
}

Where IExtendedProperty is an interface for the custom property data.

extracting Wix object properties

I dug into the Wix sdk, and found the class object. You can access the app ID with

$wix->getAppId();

If you need to access the secret, use:

$wix->getSecret();


Related Topics



Leave a reply



Submit