- Class Foo {
- Function name_none_static (){
- Echo "My name is". get_class ()."
";
- Echo "My name is". get_class ($ this )."
";
- }
- }
- // Class internal call
- $ Bar = new Foo ();
- $ Bar-> name_none_static ();
- // Class external call
- Echo "Its name is". get_class ($ bar )."
";
- ?>
Output result: My name is FooMy name is FooIts name is Foo
Get_class function (PHP 4, PHP 5)
Get_class-class name of the returned object
Description of Report a bugreject note
String get_class ([object $ obj]) returns the name of the class to which the object instance obj belongs. If obj is not an object, FALSE is returned.
Note: The class defined in the PHP Extension Library returns the name of its original definition. In PHP 4, get_class () returns the user-defined class name in lowercase, but in PHP 5, the class name defined by the class name is returned, just like the class name in the extension Library.
Note: Since PHP 5, obj is optional if it is called in the object method.
Example 1: Use get_class ()
-
Class foo {
- Function foo ()
- {
- // Implements some logic
- }
-
Function name ()
- {
- Echo "My name is", get_class ($ this), "\ n ";
- }
- }
-
// Create an object
- $ Bar = new foo ();
-
// External call
- Echo "Its name is", get_class ($ bar), "\ n ";
-
// Internal call
- $ Bar-> name ();
- ?>
Output: Its name is fooMy name is foo |