- property_exists: documentation ( source)
- var_dump: documentation ( source)
- get_object_vars: documentation ( source)
<?php
class A
{
public $a=1;
public $b=2;
public $c=3;
}
class B
{
public $a=5;
public $b=6;
public $e=7;
public $f=8;
}
$foo = new A;
$bar = new B;
foreach(get_object_vars($foo) as $name=>$value)
{
if(property_exists($bar, $name))
{
$bar->$name = $value;
}
}
var_dump($bar);