Introduction to PHP7

 

New features and changes

Summary

  • Introduction
  • Performances
  • Type declaration
  • Error handling
  • Generators

Introduction

Performances

Type declaration

<?php

    function giveMeYourString(int $ohYeah): string {
        return (string) $ohYeah;
    }

    // This will throw a TypeError exception (yeah, exception, we will see it later)
    giveMeYourString("I'm already a string I understood nothing");

    // This will work without problems
    giveMeYourString(13700);

Error handling

<?php

    try {
 
       $this->hardcoreRiskyCode();

    } catch (\Exception $exception) {

        echo $exception->getMessage();

    } catch (\Error $error) {

        echo $error->getMessage();

    } catch (\Throwable $throwable) {

        echo "Something terrible happened. Exception or Error, I just don't know";

    }

Generators

PHP7 talk

By Axel Venet

PHP7 talk

Introduction to PHP7 and its new features for Extia PHP community

  • 632