When should this and self be used?-php Tutorial

Source: Internet
Author: User
When should this and self use private static $ case_l_step_end;
Private $ single_step;
The above one can be called using self, and the following is called using this.
The written classes are instantiated objects. Only the methods in the class are recursive, private static $ case_l_step_end; this attribute is useful for recursion.
The question is:
Var_dump ($ this-> single_step); this value can be obtained if it is a number, and other things cannot be taken.
Var_dump (self: $ case_l_step_end); you can obtain the value.

When to add static member variables?


Reply to discussion (solution)

Paste your code.
Otherwise, I will post a textbook to you. would you like it?

There are a lot of code in this class. can I send it to you privately?

Paste your code.
Otherwise, I will post a textbook to you. would you like it?



Paste your code.
Otherwise, I will post a textbook to you. would you like it?

You only need to paste the relevant part.
It mainly depends on how you write

This cannot call static attributes.
Self: non-static attributes cannot be called.

 B; echo $ this-> a; // this call static property error echo self: $ B; // error in calling non-static properties by self} $ o = new test (); $ o-> run ();?>

This cannot call static attributes.
Self: non-static attributes cannot be called.

 B; echo $ this-> a; // this call static property error echo self: $ B; // error in calling non-static properties by self} $ o = new test (); $ o-> run ();?>



Thank you.

You only need to paste the relevant part.
It mainly depends on how you write



The error is that when I write if, I write =
Solved. Thank you.

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.