Hey everybody I want to let you know that I have undertaken the grueling task of getting the heck away from WordPress. I was so sick of the problems and updates I had to do all the time. I am now using my ezbloo system and I am integrating all my old posts into the new system. It sucks, but in the end, I will save bundles of time. I needed to keep things simple and that is why I created ezbloo. I'll have more on this later for you guys after I am done with the total integration of my old posts here. So if you are looking for a post and need it faster, shoot me an email and I will make it a priority. [email protected]

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 PHP7 Arrays

Arrays consist of a block of data in variables. These variables hold several different types of data. Consider this example. Since I love to ride ATV's I created an array with the different brands of ATV's. After that I echoed them out in my PHP script to show on the page. This is a very simple array. We will get into more complex arrays as these tutorials progress.
<?php
$atv = array("Honda", "Harley", "Kawasaki");
echo "I like " . $atv[0] . ", " . $atv[1] . " and " . $atv[2] . ".";
?>
  php7 arrays

Data Type NULL in PHP7

The Data Type NULL in PHP7 only holds one value and that is NULL. NULL is basically nothing, it means that nothing is in that data string. Here is an example. Let's set the $var='PHP7' and then we will change the variable to NULL then echo it out on the page.
<?php $var='PHP7'; 
echo $var; 
echo '<br>'; $var=null; 
echo $var ?>
As you  can see the variable $var was emptied and nothing is being echoed out in the second $var. If a variable is created with nothing in it is it automatically assigned NULL.

How Do We Use NULL in PHP7 Applications?

We use NULL to store nothing in a variable. However we do not put the term NULL in the variable we just leave it empty. In the future when you are working with loops you may set a variable to NULL and then fill it with some other data. null is nothing in PHP7

PHP7 Data Type Resource

A PHP7 resource is a resource loaded from outside the application. This could be a database connection or a resource to create a new file within PHP. So if you are calling a database resource it would look something like this. We will get into this more as you progress in these tutorials.
<?php
<pre>$conn = mysqli_connect(localhost,"root","dbpass","dbname");</pre>
?>
 

How is PHP7 Resource Used In Applications?

A PHP7 Resource is a way to make a call to get data or create data. You will be using several different kinds of resources in your applications. PHP RESOURCE Files for this lesson.

Video For This Lesson