1--TEST-- 2get_class() tests 3--FILE-- 4<?php 5 6class foo { 7 function bar () { 8 var_dump(get_class()); 9 } 10 function testNull () 11 { 12 try { 13 var_dump(get_class(null)); 14 } catch (TypeError $e) { 15 echo $e->getMessage(), "\n"; 16 } 17 } 18} 19 20class foo2 extends foo { 21} 22 23$f1 = new foo; 24$f2 = new foo2; 25 26$f1->bar(); 27$f2->bar(); 28 29try { 30 var_dump(get_class()); 31} catch (Error $e) { 32 echo $e->getMessage(), "\n"; 33} 34try { 35 var_dump(get_class("qwerty")); 36} catch (TypeError $e) { 37 echo $e->getMessage(), "\n"; 38} 39 40var_dump(get_class($f1)); 41var_dump(get_class($f2)); 42 43$f1->testNull(); 44 45echo "Done\n"; 46?> 47--EXPECT-- 48string(3) "foo" 49string(3) "foo" 50get_class() without arguments must be called from within a class 51get_class(): Argument #1 ($object) must be of type object, string given 52string(3) "foo" 53string(4) "foo2" 54get_class(): Argument #1 ($object) must be of type object, null given 55Done 56