PHP/MYSQL

Revisiting PHP Part VII: PHP7 Integer Division function & Anonymous Classes in PHP7

Image result for integer division

Image Credits: Slideplayer

Making division with integers had not been easy with previous versions of PHP which has usually done with “/” slash symbol. However, with PHP 7, typecasting has brought a new method of getting the job done. The name of the function is: intdiv() and it efficiently brought in for this reason by taking dual values. For instance, the numerator and denominator brings back a certain quotient which is actually a number. A typical instance is given below:

<?php

echo intdiv(45, 5), PHP_EOL; # outputs: 9

?>

Anonymous Classes in PHP7

Image result for php classes & Objects

Image  Credits:Youtube

Finally, PHP7 dawns a modern method to make objects or classes with actually naming them. These specific classes or objects can be “disconnected”-(unset) at any time. This feature is quite unique and makes creation of classes easier. The following is a typical example.

<?php

$handsonlabs_sa= new class(“Innovations_&_Solutions”){

public function __construct($problem_solving){

echo ‘Welcome to, ‘ . $ problem_solving . ‘!’ . PHP_EOL;

}

};

?>

//outputs Welcome to, Innovations_&_Solutions!

Leave a Reply

Your email address will not be published. Required fields are marked *