Data Types In Php 7 Objects Arrays Null Resource Lesson 11

Subscribe

DATA TYPES IN PHP 7

Here is the second part to the data types in PHP7. Lesson 10 we talked about Strings, Integers, Booleans, and Floats.In this lesson we are going to talk about  Objects, Arrays, NULL and Resource. Here are the files from the previous lesson if you are just joining us. Video is on page 4, you can navigate there quickly by hitting 4 at the bottom of the page.

Data Type Objects in PHP7

“Objects in PHP7” are bits of codes that we can use over and over again. One of the objectives we have as programmers is we want to write less code and have it do more for us. This is exactly what OOP, “Object Oriented Programming” does for us. Do not worry about mastering this we are going to have several lessons on it later.

Picture a vehicle in your mind. What do all vehicles have? Here is a simple list of what all vehicles would have.

  • Vin Number
  • Weight
  • Height

So in OOP we could create an “Object” that holds these values. Classes are blueprints for objects. Don’t worry about getting this down, I am just covering this because it is a PHP7 Data Type that we will go in depth later on.

//polymorphism
class Vehicle {
public $vin;
public $weight;
public $height;

public function __construct($vin, $weight, $height){
$this->vin=$vin;
$this->weight=$weight;
$this->height=$height;
}
}
$max=new Vehicle('423437', '6000', '6');
echo 'Vin# '.$max->vin.' Weight '.$max->weight.' Height '.$max->height;

Extending A Class

So when we want to extend a class so we do not have to write it over and over again we can just do this.

<?php //extend class
class Car extends Vehicle{
public $car;

public function __construct($vin, $weight, $height, $car){
parent::__construct($vin, $weight, $height);
$this->car=$car;
}
}
$auto=new Car('123412341234','6000','6', 'Chevy Cruise');
echo 'Type: '.$auto->car.' Vin#: '.$auto->vin.' Weight: '.$auto->weight.' Height '. $auto->height; ?>

How are Objects Used in PHP7?

They are used to make programming more efficient. You do not want to have to write the same codes over and over again for the same things. This is why we have OOP “Object Oriented Programming”.

objects-in-php7-oop

Data Types In Php 7 Objects Arrays Null Resource Lesson 11 was last modified: October 29th, 2021 by Maximus Mccullough

DATA TYPES IN PHP7 HOW THEY ARE USED

Pages: 1 2 3 4 Next

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.