PHPget_class () function usage example

Source: Internet
Author: User
PHPget_class () function usage example

  1. Class Foo {
  2. Function name_none_static (){
  3. Echo "My name is". get_class ()."
    ";
  4. Echo "My name is". get_class ($ this )."
    ";
  5. }
  6. }
  7. // Class internal call
  8. $ Bar = new Foo ();
  9. $ Bar-> name_none_static ();
  10. // Class external call
  11. Echo "Its name is". get_class ($ bar )."
    ";
  12. ?>

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 ()

  1. Class foo {

  2. Function foo ()
  3. {
  4. // Implements some logic
  5. }

  6. Function name ()

  7. {
  8. Echo "My name is", get_class ($ this), "\ n ";
  9. }
  10. }

  11. // Create an object

  12. $ Bar = new foo ();

  13. // External call

  14. Echo "Its name is", get_class ($ bar), "\ n ";

  15. // Internal call

  16. $ Bar-> name ();
  17. ?>

Output: Its name is fooMy name is foo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.