Home > Backend Development > PHP Tutorial > PHP object-oriented programming video material sharing

PHP object-oriented programming video material sharing

巴扎黑
Release: 2023-03-15 16:22:01
Original
1443 people have browsed it

In object-oriented programming (English: Object-oriented programming, abbreviation: OOP), an object is a whole composed of information and a description of how to process the information. It is an abstraction of the real world.

In the real world, the things we face are objects, such as computers, televisions, bicycles, etc.

The main three characteristics of the object:

The behavior of the object: what operations can be applied to the object, turning on the light and turning off the light are behaviors.

The shape of the object: how the object responds, color, size, and appearance when those methods are applied.

Representation of objects: The representation of objects is equivalent to an ID card. It specifically distinguishes the differences between the same behaviors and states.

This course teaches the basic concepts of object-oriented and related case practices, so that students can have a basic understanding of object-oriented and master the method of abstracting practical problems into class objects to solve practical problems. , master the most important core capabilities of object-oriented.

PHP object-oriented programming video material sharing

Video playback address: http://www.php.cn/course/329.html

Difficulties in this video:

1. __construct:

Built-in constructor, automatically called when the object is created. See the following code:

<? php
classConstructTest {
    private $arg1;
    private $arg2;
    public function __construct($arg1, $arg2) {
        $this->arg1 = $arg1;
        $this->arg2 = $arg2;
        print "__construct is called...\n";
    }
    public function printAttributes() {
        print &#39;$arg1 = &#39; . $this->arg1 . &#39; $arg2 = &#39; . $this->arg2 . "\n";
    }
}
$testObject = new ConstructTest("arg1", "arg2");
$testObject->printAttributes();
Copy after login

The running result is as follows:

Stephens-Air:Desktop$ php Test.php
__construct is called...
$arg1 = arg1 $arg2 = arg2

2. parent:

is used to directly call methods in the parent class in the subclass, and its function is equivalent to super in Java.

<? php
classBaseClass {
    protected $arg1;
    protected $arg2;
    function __construct($arg1, $arg2) {
        $this->arg1 = $arg1;
        $this->arg2 = $arg2;
        print "__construct is called...\n";
    }
    function getAttributes() {
        return &#39;$arg1 = &#39; . $this->arg1 . &#39; $arg2 = &#39; . $this->arg2;
    }
}
class SubClass extends BaseClass {
    protected $arg3;
    function __construct($baseArg1, $baseArg2, $subArg3) {
        parent::__construct($baseArg1, $baseArg2);
        $this->arg3 = $subArg3;
    }
    function getAttributes() {
        return parent::getAttributes() . &#39; $arg3 = &#39; . $this->arg3;
    }
}
$testObject = new SubClass("arg1", "arg2", "arg3");
print $testObject->getAttributes() . "\n";
Copy after login

The running results are as follows:

Stephens-Air:Desktop$ php Test.php
__construct is called...
$arg1 = arg1 $arg2 = arg2 $arg3 = arg3

The above is the detailed content of PHP object-oriented programming video material sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template