PHP/MYSQL

Blending with the new features in version 7+: Return Type Declarations

Correspondingly to the argument type statements, give type statements that indicate the type of output to be brought back from a methods. Noteworthy, is that fact that similar types are put back as results for return type declarations and presently for argument type statements.

For instance:

Output:

The Collection::item() method returns a type of Generator, as expected However,
it yields the following: Class: Item. Calling id() method returns 0 (integer) Class:
Item. Calling id() method returns 1 (integer) Class: Item. Calling id() method returns 2 (integer) Class:
Item. Calling id() method returns 3 (integer) Class: Item. Calling id() method returns 4 (integer) Class:
Item. Calling id() method returns 5 (integer) Class: Item. Calling id() method returns 6 (integer) Class:
Item. Calling id() method returns 7 (integer) Class: Item. Calling id() method returns 8 (integer) Class:
Item. Calling id() method returns 9 (integer) It doesn’t appear to be possible to hint the yielded type

SourceCode Courtesy: Antnee

What must be noted here is that PHP 7 now permits developers to create a return type dynamically. In the above code by github/Antnee, Collection::item()  will not appear to be executing any task (particularly if there’s no return statement, but the resultant Item type. Therefore, the resultant type in Collection::item with reference to the Item.

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