Property name precedes with length.
string(92) "O:6:"ClassA":3:{s:12:"publicMember";N;s:21:"\000ClassA\000privateMember";N;s:12:"\000*\000protected";N;}"
| property name length ^ ^ ^
| we will try to capture this part ^ ^
You ned reduce this length if you what to "convert" protected to public. For example.
class ClassA
{
public $publicMember;
private $privateMember;
protected $protected;
}
$objectA = new ClassA();
$stringA = serialize($objectA);
$converted = preg_replace_callback('@:(\d+):"\x00\*\x00@', function($match)
// ^ catch the number
// ^ ^ null symbols
{
$property_name_length = $match[1];
return ':' . ($property_name_length - 3) . ':"'; // reduce catched number and do not return \x00*\x00
}, $stringA);
var_dump(unserialize($converted));
Produces
class ClassA#2 (4) {
public $publicMember =>
NULL
private $privateMember =>
NULL
protected $protected =>
NULL
public $protected =>
NULL
}
P.S. But this code will fail when you start to store serialized like data as members values.