PHP is the abbreviation of the English hypertext preprocessing language Hypertext Preprocessor. PHP is an HTML embedded language. It is a scripting language embedded in HTML documents that is executed on the server side. The language style is similar to C language and is widely used. For this reason, Chuanzhi Podcast is giving away a series of PHP video tutorials for free! Aimed at the majority of PHP beginners and programmers who have many years of PHP development experience, we will help you get to the next level in the PHP field!
Course playback address://m.sbmmt.com/course/356.html
The teacher’s teaching style:
The teacher’s lectures are simple, clear, layer-by-layer analysis, interlocking, rigorous argumentation, rigorous structure, and use the logical power of thinking to attract students’ attention Strength, use reason to control the classroom teaching process. The teaching skills are full of wit. Various teaching methods and techniques are readily available and can be used freely and appropriately without any trace of polishing.
The more difficult points in this video should be: PHP object-oriented basics:
Although php is a very simple language to learn, this language also includes Added support for object-oriented programming. Especially with the release of php5, php's support for object-oriented has made great progress. I recently studied object-oriented programming in PHP, and I can't help but sigh. Object-oriented programming is really a very elegant programming, but the most important thing is that it is really difficult!
To learn object-oriented, of course, you must first understand what a class is, what an object is, and what is the relationship between a class and an object? I won’t go into details about the definitions of classes and objects here. I believe everyone has a basic understanding of classes and objects. Let’s mainly talk about the relationship between classes and objects: a class is a template used to generate objects, and an object is an instance of a class. I won’t go into detail on how to define classes and instantiate objects. These are very simple operations. Let’s briefly record some parts of object-oriented (many of them are my own understanding while studying. If there are any mistakes, please criticize and educate me!).
(1) Set the attributes of the class: Once you have a basic understanding of classes, you will know that different classes have different attributes. For example, it is like the commodity class, and commodities have price attributes. Personally, there is not much difference between defining attributes of a class and defining variables. What is special is that when defining attributes, you need to give the attributes of the class a visibility keyword. This visibility keyword determines the attribute. When can be accessed. Visibility keywords include: public, private, and protect. If defined using var, the default is public.
name; ?>
In the above code, the page encoding format is first set to utf-8, and then a Product class is defined. This has two attributes: name, price, and both attributes are public. Run This code will output "shirt".
There is also an operation to dynamically add attributes in PHP, $product1->haha="haha", which directly uses the instantiated method to access a non-existent attribute and dynamically adds the attribute using the assignment method. A big disadvantage of this dynamic addition of attributes is that when an object is instantiated with a class, there is no guarantee that other objects also have this attribute.
(2) Usage method in class: Usage method is to declare functions that may be used by the class in the class. Method declaration is similar to function declaration. When declaring a method, you need to add a visibility in front of the method. keyword, because of the restrictions of the visibility keyword, the method can be accessed in different places. After declaring a method in a class, we can directly instantiate an object and then use the object to access the method.
price; } } $product1=new Product(); echo $product1->name."
"; echo $product1->say(); ?>
After the above code is executed, the browser will output: "shirt", and the next line is "100". In fact, $this is a pseudo variable that represents the current object. Note that it represents the current object, not the class.
One of the more important methods among class methods is the constructor (also called the constructor method). The function of the constructor method is to be automatically called when creating an object for instantiation of the object. After PHP5, the promoted constructor is named __construct(). When we use the new operator to instantiate an object, the constructor method is automatically called to instantiate the attributes in the class according to the parameters to initialize the object. (In fact, I personally think that this construction method only provides an automatic calling mechanism. When we initialize, we automatically call the constructor and pass in the parameters, and initialize the member attributes in the class according to the passed in parameters)
name=$name; $this->price=$price; } public function say(){ return $this->price; } } $product1=new Product("衬衫",100); echo $product1->name."
"; echo $product1->say()."
"; $product2=new Product("牛仔裤",200); echo $product2->say(); ?>
After the above code is executed, "shirt, 100, 200" will be output in the browser.
The above is the detailed content of Chuanzhi Podcast PHP core basic video tutorial recommendation (resource). For more information, please follow other related articles on the PHP Chinese website!