Type hints were introduced with PHP 5. PHP 7 will add the ability to type hint on scalars and even to explicitly state what type will be returned from the function. This talk briefly goes over these added features to PHP 7.
Presented at Codemotion 2016. Discusses the beginner-level dynamics of the performance-improved PHP 7. Gain expanded knowledge of the spaceship and null coalescing operators, anonymous classes, the new error exception, and the security features of PHP 7.
Presented at Codemotion 2016. Discusses the beginner-level dynamics of the performance-improved PHP 7. Gain expanded knowledge of the spaceship and null coalescing operators, anonymous classes, the new error exception, and the security features of PHP 7.
This is a "PHP 201" presentation that was given at the December 2010 Burlington, Vermont PHP Users group meeting. Going beyond the basics, this presentation covered working with arrays, functions, and objects.
With PHP 5.6 there are some great new features. We'll go over some of these features and how to use them. This includes variadic functions, constant scalar expressions, exponentiation, splat operator, use const/function, php input, phpdbg, and more. We will also cover deprecated features in PHP 5.6. Want to get involved with upcoming release? I'll show you how you can 'make_test' to start helping out.
PHP stands for “PHP: Hypertext Preprocessor”. It is very good for creating dynamic content. PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.
Slide utilisé lors du Meetup du 16 juin 2017 organisé par l'AFUP Montpellier
Présentation des PHP Standards Recommendations (PSR). Leurs buts et l'avantage de les utiliser
Correctly understanding the eight data types in PHP is essential to a solid foundation in development. Come refresh your knowledge of the scalar types, compound types, and special data types used in PHP, and learn about proper usage of each. Review type juggling, learn some common data type traps to avoid, and how to code defensively to prevent having the data type of a variable change unexpectedly. Finally learn how unit tests can help verify that code is handling data types correctly.
I present four design patterns that make your development easier and better. Design patterns are a fantastic way to make more readable code, as they make use of common ideas that many developers know and use. These patterns are tried and tested in the enterprise world.
The first one is dependency injection. This covers putting the variables that a class needs to function preferably inside a constructor.
The second one is the factory pattern. A factory moves the responsibility of instantiating an object to a third-party class.
The third one is dependency injection. This allows us to place a class' dependencies at one time, making it easy to come back and see what the class needs to survive.
Finally, we discuss the chain of responsibility. This allows complex operations to be handled by a chain of classes. Each class in the chain determines whether it is capable of handling the request and, if so, it returns the result.
This is a "PHP 201" presentation that was given at the December 2010 Burlington, Vermont PHP Users group meeting. Going beyond the basics, this presentation covered working with arrays, functions, and objects.
With PHP 5.6 there are some great new features. We'll go over some of these features and how to use them. This includes variadic functions, constant scalar expressions, exponentiation, splat operator, use const/function, php input, phpdbg, and more. We will also cover deprecated features in PHP 5.6. Want to get involved with upcoming release? I'll show you how you can 'make_test' to start helping out.
PHP stands for “PHP: Hypertext Preprocessor”. It is very good for creating dynamic content. PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.
Slide utilisé lors du Meetup du 16 juin 2017 organisé par l'AFUP Montpellier
Présentation des PHP Standards Recommendations (PSR). Leurs buts et l'avantage de les utiliser
Correctly understanding the eight data types in PHP is essential to a solid foundation in development. Come refresh your knowledge of the scalar types, compound types, and special data types used in PHP, and learn about proper usage of each. Review type juggling, learn some common data type traps to avoid, and how to code defensively to prevent having the data type of a variable change unexpectedly. Finally learn how unit tests can help verify that code is handling data types correctly.
I present four design patterns that make your development easier and better. Design patterns are a fantastic way to make more readable code, as they make use of common ideas that many developers know and use. These patterns are tried and tested in the enterprise world.
The first one is dependency injection. This covers putting the variables that a class needs to function preferably inside a constructor.
The second one is the factory pattern. A factory moves the responsibility of instantiating an object to a third-party class.
The third one is dependency injection. This allows us to place a class' dependencies at one time, making it easy to come back and see what the class needs to survive.
Finally, we discuss the chain of responsibility. This allows complex operations to be handled by a chain of classes. Each class in the chain determines whether it is capable of handling the request and, if so, it returns the result.
PHP7 brings a tremendous number of new features. Tonight, we will take a look at the null coalesce operator, new execution order (uniform variable syntax), new exceptions and more.
At age 9 a Canadian boy called Chris Hadfield witnessed the landing of Apollo 11’s lunar module on the moon. That night he decided he wanted to be an astronaut. Every time he had to make some decision in life, he picked the option that brought him closer to fulfilling that dream.
He actually became an astronaut and is now quite famous for his work as commander of the International Space Station (ISS).
Being an astronaut is a lot of work. It’s life-endangering, physically demanding and mentally exhausting. You need to make the right decisions under high pressure and live with people in cramped rooms. Compared to this, the life of a programmer seems easy peasy lemon squeezy.
Yet there’s a great number of things that we, developers, can learn from Chris’s perseverance, his optimism, his way of life and the rules and procedures he applies to prevent major incidents.
There are so many interesting ways to authenticate a user: via an API token, social login, a traditional HTML form or anything else you can dream up. But until now, creating a custom authentication system in Symfony has meant a lot of files and a lot of complexity. Introducing Guard: a simple, but expandable authentication system built on top of the security component and introduced in Symfony 2.8. Want to authenticate via an API token? Great - that's just one class. Social login? Easy! Have some crazy legacy central authentication system? In this talk, we'll show you how you'd implement any of these in your application today. Don't get me wrong - you'll still need to do some work. But finally, the path will be clear and joyful.
Symfony: Your Next Microframework (SymfonyCon 2015)Ryan Weaver
Microservices are a huge trend, and microframeworks are perfect for them: put together just a few files, write some code, and your done!
But Symfony is a big framework, right? Wrong! Symfony can be as small as a single file!
In this talk, we'll learn how to use Symfony as a micro-framework for your next project. Your app will stay small and clear, but without needing to give up the features or third-party bundles that you love. And if the project grows, it can evolve naturally into a full Symfony project.
So yes, Symfony can also be a microframework. Tell the world!
Andres Gutierrez "Phalcon 3.0, Zephir & PHP7"Fwdays
Phalcon is a web framework written as an extension PHP seeking to improve the performance, taking advantage of low-level resources that no other traditional framework can take. Phalcon is a full stack framework, also providing a Micro approach, a template engine called Volt, the first ODM and ORM for PHP written in Zephir/C and many other components that ease the life of developers when creating web applications.
Initial versions of Phalcon were created using C directly as main language. Given the framework success many developers were willing to help, however it required C knowledge and PHP internals expertise, this made it difficult for them the possibility of help.
Since Phalcon 2, we started using Zephir, a brand new, high-level and compiled language created by the core team, that made our collaborators can help out easier to our project making it robust and stable.
Best of all, Zephir allows the easy creation of extensions for both PHP5 and PHP7. An extension can sometimes improve performance, reduce overall memory and processor usage and protect intelectual property.
The talk will be about the project evolution, Phalcon 3 as framework and the advantages of using Zephir for building extensions, also success cases and best practices in terms of performance.
Commands, events, queries - three types of messages that travel through your application. Some originate from the web, some from the command-line. Your application sends some of them to a database, or a message queue. What is the ideal infrastructure for an application to support this on-going stream of messages? What kind of architectural design fits best?
This talk provides answers to these questions: we take the *hexagonal* approach to software architecture. We look at messages, how they cross boundaries and how you can make steady communication lines between your application and other systems, like web browsers, terminals, databases and message queues.
You will learn how to separate the technical aspects of these connections from the core behavior of your application by implementing design patterns like the *command bus*, and design principles like *dependency inversion*.
Learn how to write scripted load tests in PHP to run against your system without breaking the bank. Jason will cover not only the importance of load testing, but share stories of how load tests uncovered problems that would otherwise not have been discovered until production. Also, learn how to use load testing to learn how to deal with large traffic sites without needing to be employed by a large scale site first. We’ll be using RedLine13, an almost free load testing tool that is at the same time inexpensive, easy, and effective.
PHP 8.0 comes with many long-awaited features: A just-in-time compiler, attributes, union types, and named arguments are just a small part of the list. As a major version, it also includes some backward-incompatible changes, which are centered around stricter error handling and enhanced type safety. Let's have an overview of the important changes in PHP 8.0 and how they might affect you!
Talk I gave to The Coding Machine about PHP 8. Overview of the RFC process and which QoL, features and notable BC breaks before finishing on some performance improvements.
Those slides, inspired by the works and ideas of many, are a state of what PHP gets in upgrades as of Q4 2018.
Market share and evolution.
PHP 7.3
PHP 7.4
PHP 8.0
An overview of the latest news and interesting developments across PHP from January 2019: new language features, RFCs, community news, upcoming conferences, and the latest versions of popular frameworks and platforms.
An overview of the latest news and interesting developments across PHP from November 2018: new language features, RFCs, community news, upcoming conferences, and the latest versions of popular frameworks and platforms.
An overview of the latest news and interesting developments across PHP from October 2018: new language features, RFCs, community news, upcoming conferences, and the latest versions of popular frameworks and platforms.
An overview of the latest news and interesting developments across PHP from September 2018: new language features, RFCs, community news, upcoming conferences, and the latest versions of popular frameworks and platforms.
An overview of the latest news and interesting developments across PHP from July 2018: new language features, RFCs, community news, upcoming conferences, and the latest versions of popular frameworks and platforms.
An overview of the latest news and interesting developments across PHP from April 2018: new language features, RFCs, community news, upcoming conferences, and the latest versions of popular frameworks and platforms.
An overview of the latest news and interesting developments across PHP from March 2018: new language features, RFCs, community news, upcoming conferences, and the latest versions of popular frameworks and platforms.
An overview of the latest news and interesting developments across PHP from February 2018: new language features, RFCs, community news, upcoming conferences and the latest versions of popular frameworks and platforms.
An overview of the latest news and interesting developments across PHP from November & December 2017: new language features, RFCs, community news, upcoming conferences and the latest versions of popular frameworks and platforms.
Last Month in PHP - June through Mid-July 2017Eric Poe
An overview of the latest news and interesting developments across PHP from June through Mid-July 2017: new language features, RFCs, community news, upcoming conferences and the latest versions of popular frameworks and platforms.
An overview of the latest news and interesting developments across PHP from April 2017: new language features, RFCs, community news, upcoming conferences and the latest versions of popular frameworks and platforms.
An overview of the latest news and interesting developments across PHP from March 2017: new language features, RFCs, community news, upcoming conferences and the latest versions of popular frameworks and platforms.
An overview of the latest news and interesting developments across PHP from February 2017: new language features, RFCs, community news, upcoming conferences and the latest versions of popular frameworks and platforms.
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Anthony Dahanne
Les Buildpacks existent depuis plus de 10 ans ! D’abord, ils étaient utilisés pour détecter et construire une application avant de la déployer sur certains PaaS. Ensuite, nous avons pu créer des images Docker (OCI) avec leur dernière génération, les Cloud Native Buildpacks (CNCF en incubation). Sont-ils une bonne alternative au Dockerfile ? Que sont les buildpacks Paketo ? Quelles communautés les soutiennent et comment ?
Venez le découvrir lors de cette session ignite
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamtakuyayamamoto1800
In this slide, we show the simulation example and the way to compile this solver.
In this solver, the Helmholtz equation can be solved by helmholtzFoam. Also, the Helmholtz equation with uniformly dispersed bubbles can be simulated by helmholtzBubbleFoam.
Code reviews are vital for ensuring good code quality. They serve as one of our last lines of defense against bugs and subpar code reaching production.
Yet, they often turn into annoying tasks riddled with frustration, hostility, unclear feedback and lack of standards. How can we improve this crucial process?
In this session we will cover:
- The Art of Effective Code Reviews
- Streamlining the Review Process
- Elevating Reviews with Automated Tools
By the end of this presentation, you'll have the knowledge on how to organize and improve your code review proces
Cyaniclab : Software Development Agency Portfolio.pdfCyanic lab
CyanicLab, an offshore custom software development company based in Sweden,India, Finland, is your go-to partner for startup development and innovative web design solutions. Our expert team specializes in crafting cutting-edge software tailored to meet the unique needs of startups and established enterprises alike. From conceptualization to execution, we offer comprehensive services including web and mobile app development, UI/UX design, and ongoing software maintenance. Ready to elevate your business? Contact CyanicLab today and let us propel your vision to success with our top-notch IT solutions.
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxrickgrimesss22
Discover the essential features to incorporate in your Winzo clone app to boost business growth, enhance user engagement, and drive revenue. Learn how to create a compelling gaming experience that stands out in the competitive market.
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Globus
The U.S. Geological Survey (USGS) has made substantial investments in meeting evolving scientific, technical, and policy driven demands on storing, managing, and delivering data. As these demands continue to grow in complexity and scale, the USGS must continue to explore innovative solutions to improve its management, curation, sharing, delivering, and preservation approaches for large-scale research data. Supporting these needs, the USGS has partnered with the University of Chicago-Globus to research and develop advanced repository components and workflows leveraging its current investment in Globus. The primary outcome of this partnership includes the development of a prototype enterprise repository, driven by USGS Data Release requirements, through exploration and implementation of the entire suite of the Globus platform offerings, including Globus Flow, Globus Auth, Globus Transfer, and Globus Search. This presentation will provide insights into this research partnership, introduce the unique requirements and challenges being addressed and provide relevant project progress.
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfJay Das
With the advent of artificial intelligence or AI tools, project management processes are undergoing a transformative shift. By using tools like ChatGPT, and Bard organizations can empower their leaders and managers to plan, execute, and monitor projects more effectively.
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus
As part of the DOE Integrated Research Infrastructure (IRI) program, NERSC at Lawrence Berkeley National Lab and ALCF at Argonne National Lab are working closely with General Atomics on accelerating the computing requirements of the DIII-D experiment. As part of the work the team is investigating ways to speedup the time to solution for many different parts of the DIII-D workflow including how they run jobs on HPC systems. One of these routes is looking at Globus Compute as a way to replace the current method for managing tasks and we describe a brief proof of concept showing how Globus Compute could help to schedule jobs and be a tool to connect compute at different facilities.
A Comprehensive Look at Generative AI in Retail App Testing.pdfkalichargn70th171
Traditional software testing methods are being challenged in retail, where customer expectations and technological advancements continually shape the landscape. Enter generative AI—a transformative subset of artificial intelligence technologies poised to revolutionize software testing.
Check out the webinar slides to learn more about how XfilesPro transforms Salesforce document management by leveraging its world-class applications. For more details, please connect with sales@xfilespro.com
If you want to watch the on-demand webinar, please click here: https://www.xfilespro.com/webinars/salesforce-document-management-2-0-smarter-faster-better/
Into the Box Keynote Day 2: Unveiling amazing updates and announcements for modern CFML developers! Get ready for exciting releases and updates on Ortus tools and products. Stay tuned for cutting-edge innovations designed to boost your productivity.
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteGoogle
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
👉👉 Click Here To Get More Info 👇👇
https://sumonreview.com/ai-pilot-review/
AI Pilot Review: Key Features
✅Deploy AI expert bots in Any Niche With Just A Click
✅With one keyword, generate complete funnels, websites, landing pages, and more.
✅More than 85 AI features are included in the AI pilot.
✅No setup or configuration; use your voice (like Siri) to do whatever you want.
✅You Can Use AI Pilot To Create your version of AI Pilot And Charge People For It…
✅ZERO Manual Work With AI Pilot. Never write, Design, Or Code Again.
✅ZERO Limits On Features Or Usages
✅Use Our AI-powered Traffic To Get Hundreds Of Customers
✅No Complicated Setup: Get Up And Running In 2 Minutes
✅99.99% Up-Time Guaranteed
✅30 Days Money-Back Guarantee
✅ZERO Upfront Cost
See My Other Reviews Article:
(1) TubeTrivia AI Review: https://sumonreview.com/tubetrivia-ai-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
Experience our free, in-depth three-part Tendenci Platform Corporate Membership Management workshop series! In Session 1 on May 14th, 2024, we began with an Introduction and Setup, mastering the configuration of your Corporate Membership Module settings to establish membership types, applications, and more. Then, on May 16th, 2024, in Session 2, we focused on binding individual members to a Corporate Membership and Corporate Reps, teaching you how to add individual members and assign Corporate Representatives to manage dues, renewals, and associated members. Finally, on May 28th, 2024, in Session 3, we covered questions and concerns, addressing any queries or issues you may have.
For more Tendenci AMS events, check out www.tendenci.com/events
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
Unleash Unlimited Potential with One-Time Purchase
BoxLang is more than just a language; it's a community. By choosing a Visionary License, you're not just investing in your success, you're actively contributing to the ongoing development and support of BoxLang.
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Mind IT Systems
Healthcare providers often struggle with the complexities of chronic conditions and remote patient monitoring, as each patient requires personalized care and ongoing monitoring. Off-the-shelf solutions may not meet these diverse needs, leading to inefficiencies and gaps in care. It’s here, custom healthcare software offers a tailored solution, ensuring improved care and effectiveness.
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns
Unlocking Business Potential: Tailored Technology Solutions by Prosigns
Discover how Prosigns, a leading technology solutions provider, partners with businesses to drive innovation and success. Our presentation showcases our comprehensive range of services, including custom software development, web and mobile app development, AI & ML solutions, blockchain integration, DevOps services, and Microsoft Dynamics 365 support.
Custom Software Development: Prosigns specializes in creating bespoke software solutions that cater to your unique business needs. Our team of experts works closely with you to understand your requirements and deliver tailor-made software that enhances efficiency and drives growth.
Web and Mobile App Development: From responsive websites to intuitive mobile applications, Prosigns develops cutting-edge solutions that engage users and deliver seamless experiences across devices.
AI & ML Solutions: Harnessing the power of Artificial Intelligence and Machine Learning, Prosigns provides smart solutions that automate processes, provide valuable insights, and drive informed decision-making.
Blockchain Integration: Prosigns offers comprehensive blockchain solutions, including development, integration, and consulting services, enabling businesses to leverage blockchain technology for enhanced security, transparency, and efficiency.
DevOps Services: Prosigns' DevOps services streamline development and operations processes, ensuring faster and more reliable software delivery through automation and continuous integration.
Microsoft Dynamics 365 Support: Prosigns provides comprehensive support and maintenance services for Microsoft Dynamics 365, ensuring your system is always up-to-date, secure, and running smoothly.
Learn how our collaborative approach and dedication to excellence help businesses achieve their goals and stay ahead in today's digital landscape. From concept to deployment, Prosigns is your trusted partner for transforming ideas into reality and unlocking the full potential of your business.
Join us on a journey of innovation and growth. Let's partner for success with Prosigns.
4. PHP5 Type Hinting Example
<?php
/**
* Type Hinting in PHP 5 is only for classes,
* interfaces, & callable
*
* @param DateTime $timestamp
* @return string
*/
function getDayOfWeek(DateTime $timestamp)
{
return $timestamp->format('l');
}
$times = [];
$times[] = new DateTime('now');
$times[] = new DateTimeImmutable('+3 days');
foreach($times as $time) {
printf("Today is %sn",
getDayOfWeek($time));
}
5. PHP5 Type Hinting Example
<?php
/**
* Type Hinting in PHP 5 is only for classes,
* interfaces, & callable
*
* @param DateTime $timestamp
* @return string
*/
function getDayOfWeek(DateTime $timestamp)
{
return $timestamp->format('l');
}
$times = [];
$times[] = new DateTime('now');
$times[] = new DateTimeImmutable('+3 days');
foreach($times as $time) {
printf("Today is %sn",
getDayOfWeek($time));
}
Today is Thursday
Fatal error: Argument 1 passed to
getDayOfWeek() must be an instance of
DateTime, instance of DateTimeImmutable
given, called in /vagrant_data/
php5TypeHint.php on line 19 and defined in /
vagrant_data/php5TypeHint.php on line 9
6. PHP5 Type Hinting Example
<?php
/**
* Type Hinting in PHP 5 is only for classes,
* interfaces, & callable
*
* @param DateTimeInterface $timestamp
* @return string
*/
function getDayOfWeek(DateTimeInterface
$timestamp)
{
return $timestamp->format('l');
}
$times = [];
$times[] = new DateTime('now');
$times[] = new DateTimeImmutable('+3 days');
foreach($times as $time) {
printf("Today is %sn",
getDayOfWeek($time));
}
7. PHP5 Type Hinting Example
<?php
/**
* Type Hinting in PHP 5 is only for classes,
* interfaces, & callable
*
* @param DateTimeInterface $timestamp
* @return string
*/
function getDayOfWeek(DateTimeInterface
$timestamp)
{
return $timestamp->format('l');
}
$times = [];
$times[] = new DateTime('now');
$times[] = new DateTimeImmutable('+3 days');
foreach($times as $time) {
printf("Today is %sn",
getDayOfWeek($time));
}
Today is Thursday
Today is Sunday
8. PHP 7 Scalar Type Hinting
PHP 5 Type Hinting +++ Scalars
• Strings
• Integers
• Floats
• Booleans
9. Scalar Type Hinting
• Not turned on by default
• Turn on by making `declare(strict_types=1);` the
first statement in your file
• Only strict on the file with the function call
13. PHP7 Scalar Type Hinting
Example 1: Turned On
<?php
declare(strict_types=1);
/**
* @param int $number
* @param string $street
* @param string $apt
* @return string
*/
function createStreetAddress(int $number,
string $street, string $apt = null)
{
if ($apt) {
return sprintf('%d %s, #%s', $number,
$street, $apt);
} else {
return sprintf('%d %s', $number,
$street);
}
}
echo createStreetAddress(221, "Baker St",
"B") . PHP_EOL;
echo createStreetAddress("221", "Baker St",
"B") . PHP_EOL;
221 Baker St, #B
Fatal error: Argument 1 passed to
createStreetAddress() must be of the type
integer, string given, called in /
vagrant_data/php7TypeHint.php on line 20 and
defined in /vagrant_data/php7TypeHint.php on
line 10
14. Introducing… return types
• Completely optional
• Declare strict same as for Scalar Type Hinting
• Only strict on the file with the function
declaration
• Tells the compiler that we expect to get
something of type Foo out of the function call
15. PHP 7 Return Types
Example 1: DateTime
<?php
declare(strict_types=1);
/**
* @return DateTime
*/
function getCurrentTime() : DateTime {
return new DateTime('now');
}
echo getCurrentTime()->format('l') . PHP_EOL;
16. PHP 7 Return Types
Example 1: DateTime
<?php
declare(strict_types=1);
/**
* @return DateTime
*/
function getCurrentTime() : DateTime {
return new DateTime('now');
}
echo getCurrentTime()->format('l') . PHP_EOL;
Thursday
17. PHP 7 Return Types
Example 1: Calculator
<?php
declare(strict_types=1);
/**
* @param int $num
* @param int $denom
* @return int
*/
function divide(int $num, int $denom) : int {
if (0 === $denom) {
return 9999999999;
} else {
return $num / $denom;
}
}
echo divide(7, 3) . PHP_EOL;
18. PHP 7 Return Types
Example 1: Calculator
<?php
declare(strict_types=1);
/**
* @param int $num
* @param int $denom
* @return int
*/
function divide(int $num, int $denom) : int {
if (0 === $denom) {
return 9999999999;
} else {
return $num / $denom;
}
}
echo divide(7, 3) . PHP_EOL;
Fatal error: Return value of divide() must be
of the type integer, float returned in /
vagrant_data/php7ReturnType.php on line 13 in
/vagrant_data/php7ReturnType.php on line 13
19. PHP 7 Return Types
Example 1: Calculator
<?php
declare(strict_types=1);
/**
* @param int $num
* @param int $denom
* @return float
*/
function divide(int $num, int $denom) : float
{
if (0 === $denom) {
return 9999999999;
} else {
return $num / $denom;
}
}
echo divide(7, 3) . PHP_EOL;
20. PHP 7 Return Types
Example 1: Calculator
<?php
declare(strict_types=1);
/**
* @param int $num
* @param int $denom
* @return float
*/
function divide(int $num, int $denom) : float
{
if (0 === $denom) {
return 9999999999;
} else {
return $num / $denom;
}
}
echo divide(7, 3) . PHP_EOL;
2.3333333333333
21. Great. PHP Just Got Hard.
Again.
• No. These are optional
• Weak Typing is still the default
• Strict typing forces the programmer to think more
clearly about a function’s input/output
• Think: “Filter input; escape output.”
• Leads the way to compiling PHP to Opcode
• Compiler can catch certain bugs before a user will
22. More Information
• Scalar Type Hinting & Return Types - RFC:
https://wiki.php.net/rfc/scalar_type_hints_v5
• Anthony Ferrara’s blog post about this:
http://blog.ircmaxell.com/2015/02/scalar-types-
and-php.html
• Building & Testing PHP 7:
http://akrabat.com/building-and-testing-php7/