Examples of extensions and inheritance usages of PHP classes _php tutorial

Source: Internet
Author: User

Examples of extensions and inheritance usages for PHP classes


The examples in this article describe the extension and inheritance usage of PHP classes. Share to everyone for your reference. Specific as follows:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

Class Thread

{

var $topic; Post Topic

var $body; Post Content

var $date; Post release time

var $author; Post author

function thread for initializing variables, etc.

function Thread ()

{

Initialize variables

}

function Send to submit a new post

function Send ()

{

To detect the legality of a variable and perform an insert operation to store the variable in the database

}

function edit for editing posts

function Edit ()

{

Perform update operation after checking the legality of variables store variables in the database

}

function Delete to delete a post

function Delete ()

{

When the author's permissions are detected, the relevant data is deleted from the database

}

}

Class Mainthread extends Thread

{

var $id; Post Number

var $board; The discussion area where the post is located

var $allowreply; Whether to allow replies

constructors, for initializing variables

function Mainthread ($id, $board, $allowreply)

{

Used to initialize variables

}

function Send ()

{

To detect the legality of a variable and perform an insert operation to store the variable in the database

Parent::send (); The Send function that is used to call the base class

}

function Edit ()

{

Perform update operation after checking the legality of variables store variables in the database

Parent::edit (); The edit function to call the base class

}

}

$th = new Thread; Create a new object

if ($th instanceof thread)//If the object $th is of type thread, output Yes

echo "Yes";

Else

echo "No";

?>

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/1020292.html www.bkjia.com true http://www.bkjia.com/PHPjc/1020292.html techarticle Examples of extension and inheritance usages of PHP classes This article describes the extension and inheritance usage of PHP classes. Share to everyone for your reference. Specific as follows:? 1 2 3 4 5 6 7 8 9 Ten ...

  • 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.