FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Design-patterns/prototype.php at master · LaughingMeMe/Design-patterns · GitHub
LaughingMeMe
/
Design-patterns
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Design-patterns
/
prototype.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
28 lines (23 loc) · 700 Bytes
Breadcrumbs
Design-patterns
/
prototype.php
Copy path
File metadata and controls
28 lines (23 loc) · 700 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
//原型模式,用于出来创建成本较高或者初始信息相对不变的对象
class
student{
public
function
__construct
(
$
class
,
$
school
,
$
teacherName
,
$
id
){
$
this
->
class
=
$
class
;
$
this
->
school
=
$
school
;
$
this
->
teacherName
=
$
teacherName
;
$
this
->
id
=
$
id
;
}
public
$
class
;
public
$
school
;
public
$
teacherName
;
}
$
studentA
=
new
student
(
1
,
2
,
3
,
4
);
$
studentB
=
clone
$
studentA
;
var_dump
(
$
studentA
);
var_dump
(
$
studentB
);
//两个学生拥有相同的班级、学校、老师名字的,所以可以采用原形模式,获取一份原对象的拷贝,初始化信息相对不变的情况下
$
studentA
->
id
=
1
;
$
studentB
->
id
=
2
;
var_dump
(
$
studentA
);
var_dump
(
$
studentB
);
?>
Back
|
FazBrowse Home
|
New Git URL