Constructor

Ultimate PHP and MySQL Web Development Object Oriented Programming
4 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€90.67
List Price:  €126.95
You save:  €36.27
£76.85
List Price:  £107.59
You save:  £30.74
CA$141.59
List Price:  CA$198.23
You save:  CA$56.64
A$162.72
List Price:  A$227.82
You save:  A$65.09
S$133.63
List Price:  S$187.09
You save:  S$53.45
HK$777.25
List Price:  HK$1,088.19
You save:  HK$310.93
CHF 85.07
List Price:  CHF 119.10
You save:  CHF 34.03
NOK kr1,053.17
List Price:  NOK kr1,474.49
You save:  NOK kr421.31
DKK kr676.62
List Price:  DKK kr947.30
You save:  DKK kr270.67
NZ$176.33
List Price:  NZ$246.88
You save:  NZ$70.54
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
৳12,147.82
List Price:  ৳17,007.43
You save:  ৳4,859.61
₹8,532.99
List Price:  ₹11,946.53
You save:  ₹3,413.54
RM443.65
List Price:  RM621.13
You save:  RM177.48
₦153,586.63
List Price:  ₦215,027.43
You save:  ₦61,440.80
₨28,045.28
List Price:  ₨39,264.52
You save:  ₨11,219.23
฿3,416.65
List Price:  ฿4,783.45
You save:  ฿1,366.80
₺3,800.65
List Price:  ₺5,321.07
You save:  ₺1,520.41
B$569.06
List Price:  B$796.71
You save:  B$227.64
R1,906.30
List Price:  R2,668.90
You save:  R762.59
Лв178
List Price:  Лв249.20
You save:  Лв71.20
₩144,941.59
List Price:  ₩202,924.02
You save:  ₩57,982.43
₪372.93
List Price:  ₪522.12
You save:  ₪149.19
₱5,697.42
List Price:  ₱7,976.62
You save:  ₱2,279.19
¥14,508.77
List Price:  ¥20,312.86
You save:  ¥5,804.09
MX$2,028.51
List Price:  MX$2,840
You save:  MX$811.48
QR364.51
List Price:  QR510.33
You save:  QR145.82
P1,383.62
List Price:  P1,937.13
You save:  P553.50
KSh12,918.70
List Price:  KSh18,086.70
You save:  KSh5,168
E£5,058.95
List Price:  E£7,082.73
You save:  E£2,023.78
ብር13,161.65
List Price:  ብር18,426.83
You save:  ብር5,265.18
Kz91,190.88
List Price:  Kz127,670.88
You save:  Kz36,480
CLP$94,942.50
List Price:  CLP$132,923.30
You save:  CLP$37,980.80
CN¥729.70
List Price:  CN¥1,021.61
You save:  CN¥291.91
RD$6,314.02
List Price:  RD$8,839.88
You save:  RD$2,525.86
DA13,324.71
List Price:  DA18,655.13
You save:  DA5,330.41
FJ$232.92
List Price:  FJ$326.09
You save:  FJ$93.17
Q771.72
List Price:  Q1,080.44
You save:  Q308.71
GY$20,918.72
List Price:  GY$29,287.05
You save:  GY$8,368.32
ISK kr13,121.68
List Price:  ISK kr18,370.88
You save:  ISK kr5,249.20
DH951.07
List Price:  DH1,331.53
You save:  DH380.46
L1,770.84
List Price:  L2,479.24
You save:  L708.40
ден5,601.04
List Price:  ден7,841.69
You save:  ден2,240.64
MOP$801.10
List Price:  MOP$1,121.57
You save:  MOP$320.47
N$1,876.81
List Price:  N$2,627.61
You save:  N$750.80
C$3,678.74
List Price:  C$5,150.38
You save:  C$1,471.64
रु13,655.52
List Price:  रु19,118.28
You save:  रु5,462.75
S/367.11
List Price:  S/513.97
You save:  S/146.86
K412.55
List Price:  K577.59
You save:  K165.03
SAR375.22
List Price:  SAR525.33
You save:  SAR150.10
ZK2,777.13
List Price:  ZK3,888.09
You save:  ZK1,110.96
L450.87
List Price:  L631.24
You save:  L180.36
Kč2,282.80
List Price:  Kč3,196.01
You save:  Kč913.21
Ft36,866.49
List Price:  Ft51,614.57
You save:  Ft14,748.07
SEK kr992.27
List Price:  SEK kr1,389.23
You save:  SEK kr396.95
ARS$107,405.80
List Price:  ARS$150,372.42
You save:  ARS$42,966.62
Bs690.86
List Price:  Bs967.24
You save:  Bs276.37
COP$416,197.46
List Price:  COP$582,693.09
You save:  COP$166,495.63
₡50,373.55
List Price:  ₡70,524.99
You save:  ₡20,151.43
L2,558.08
List Price:  L3,581.42
You save:  L1,023.33
₲802,182.90
List Price:  ₲1,123,088.15
You save:  ₲320,905.25
$U4,223.69
List Price:  $U5,913.34
You save:  $U1,689.64
zł385.81
List Price:  zł540.14
You save:  zł154.33
Already have an account? Log In

Transcript

Hello, in this video we are going to cover constructors. So a constructor is a function that is run as soon as you create a object for the class. So we created objects here. So this is one and it could be used for initial setup of class, the format of a constructor, public function. And what you do is you call it underscore, underscore, Doctor, like so. And now, I'm just gonna say for echo here, that's just gonna say, I began.

I pour a gallon apparently. And I will also put this in a div and I'll just do a bit of inline styling. Go equals So far and that is an open interest in give me narrow political muscle. Yep, there we go. I made a mistake. It's an unscored score construct not construct called a construct.

But I put any armor at the end my bad. So if I actually removed all this code, and literally or if I remove this as well, let me show you up and we get nothing. If I put that back in, so we haven't used any of the properties, yet, we've only actually created the classes. We have a phase I have begun. So initially, this function Always caught if you don't explicitly create your own constructor, the compiler will create a background constructor that is a requirement, but it will there always will be one it's good to have one there and to set up initial value and you know instead of you know this, we could put something like this. Copy this.

He could set these up. No arrows fantastic. And if you just print them out for the dollar OBJ print info. It prints out all the info. So it's a great way of setting up variables in a site, we can make it a bit more dynamic, because at the end of the day, this is a function. And like any other function, if you know what the functions policy, we highly recommend do that.

But like any other function of said function like a million times, I will say one more time, like any other function, you can pass values in my thinking, how do you do that, let me leave you with this. You can also create object objects for flight this that should make it a bit more obvious now. So here we have a call and what this is, you know, same thing as not having it there. But this is showing you that it is calling the constructor. So, what I want you to do is extend the constructor. So, he takes in three variables, one the speed of acceleration and one for wheels.

And then you pass in three parameters here for each vehicle. So that way you can set different speed acceleration and we'll You know, properties. And that's it for the constructor. Any questions, feel free to pop me a message. And as usual, I look forward to seeing you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.