<?php class A{ function test(){ echo 'A'; } } class B{ function test(){ echo 'B'; } } $b='B'; $a=new $b(); $a->test(); ?>