Returning to PHP: Mixing with the new highlights in adaptation 7+: Scalar Sort Declarations

Image courtesy: Developer Academy

Over the course of the next few months I will be taking a quick look at some new features of PHP such as:

  1. Scalar type declarations : They usually come in two flavours
    1. Coercive (default) and strict: Both refer to un-dynamic form of variable declarations. It is important to state here that prior to now, strings, numeric variables in PHP where loosely typed. That is, they were neither coercive, nor strict.
    2. These (Coercive (default) and strict) largely applies to: strings (string), integers (int), floating-point numbers (float), and Booleans (bool). These complement other kinds of types earlier introduced in Php 5 namely class names, interfaces, array and callable respectively.

Output

int(690) int(690)

Explanation: The above example depicts a standalone method or function with coercive and strict types respectively. Pay particular attention to how the int $abosolute_val and $bin_val were handled in the output using php var_dump output function. The second var_dump had quotes which in earlier versions of php would not output integers but rather, a type error.

ABOUT THE AUTHOR

IMG_20160116_124651

About the Author: Oluwatobi Owoeye has over seventeen years’ experience in Computer Systems and Technologies with several evidence based results. He has worked in several Information Technology projects. A published Author and currently specializing in Robotics & Mobile Computing: Analytics, Computer Vision, Distributed & Parallel Computing, and Machine Learning.

Published Books: Click Here

LinkedIn Professional Network: Click Here for LinkedIn Profile
Facebook Profile: Click Here for my Facebook Handle

Tel: 2348034478125 (whats-app Number),

+2349081395295,

+2348023169043,

+2347052912805