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 26set_error_handler(function ($severity, $message, $file, $line) { 27 throw new Exception($message); 28}); 29try { 30 $f1->bar(); 31} catch (Exception $e) { 32 echo $e->getMessage() . "\n"; 33} 34set_error_handler(null); 35 36$f2->bar(); 37 38try { 39 var_dump(get_class()); 40} catch (Error $e) { 41 echo $e->getMessage(), "\n"; 42} 43try { 44 var_dump(get_class("qwerty")); 45} catch (TypeError $e) { 46 echo $e->getMessage(), "\n"; 47} 48 49var_dump(get_class($f1)); 50var_dump(get_class($f2)); 51 52$f1->testNull(); 53 54echo "Done\n"; 55?> 56--EXPECTF-- 57Calling get_class() without arguments is deprecated 58 59Deprecated: Calling get_class() without arguments is deprecated in %s on line %d 60string(3) "foo" 61get_class() without arguments must be called from within a class 62get_class(): Argument #1 ($object) must be of type object, string given 63string(3) "foo" 64string(4) "foo2" 65get_class(): Argument #1 ($object) must be of type object, null given 66Done 67