PHP Classes

Learn New PHP 8 Features: Examples of how to use PHP 8 new features

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 199 This week: 1All time: 8,492 This week: 35Up
Version License PHP version Categories
php-8 1.0.0BSD License8Language, PHP 8
Description 

Author

This package provides examples of how to use PHP 8 new features.

It provides several script and classes that demonstrate how to use PHP 8 new features. Currently it shows features like:

- Call class function accessing the object class

- Promoting values passed to class constructor to class object properties

- Using the match expression to assign values according to patterns that an input value matches

- Functions that can return mixed values

- Functions with named arguments

- Catching exceptions without using the exception object that is thrown

- Call classes only of the objects are not null

- Throwing exceptions with any type of value

- Defining functions with parameter lists that can end with a comma

- Taking class function parameters that can be of multiple classes

Innovation Award
PHP Programming Innovation award winner
January 2022
Winner
PHP 8 introduces many excellent features that PHP developers want.

To take advantage of those features, you need to learn more about them.

One way to learn about PHP 8 new features is to see some code examples of using those features in practice.

This package provides example scripts that show how to use PHP 8 new features calling PHP classes taking advantage of those features.

Manuel Lemos
Picture of Allan Kibet
Name: Allan Kibet <contact>
Classes: 4 packages by
Country: United Kingdom
Age: ???
All time rank: 2444112 in United Kingdom
Week rank: 41 Up4 in United Kingdom Up
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

Example

<?php

// Function can take multiple input types
function display_length(int|float $length) {
    echo
"The length is: {$length} <br />";
}

display_length(22.56);

display_length(10);

class
Customer
{
    public function
__toString(): string
   
{
        return
"I am the Customer class";
    }
}

class
Employee
{
    public function
__toString(): string
   
{
        return
"I am the Customer class";
    }
}

function
which_class(Customer|Employee $obj) {
    echo
$obj;
}

$obj = new Customer();

which_class($obj);


Details

php-8

Learning new PHP 8 features


  Files folder image Files (15)  
File Role Description
Files folder image.idea (4 files)
Plain text file call_class_static_on_object.php Class Class source
Plain text file constructor_property_promotion.php Class Class source
Accessible without login Plain text file match_expression.php Aux. Auxiliary script
Accessible without login Plain text file mixed_return_types.php Aux. Auxiliary script
Accessible without login Plain text file named_arguments.php Aux. Auxiliary script
Accessible without login Plain text file non_capturing_catch.php Example Example script
Plain text file null_safe_operator.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file throw_exception.php Example Example script
Accessible without login Plain text file trailing_comma.php Aux. Auxiliary script
Accessible without login Plain text file union_types.php Example Example and class source

  Files folder image Files (15)  /  .idea  
File Role Description
  Accessible without login Plain text file modules.xml Data Auxiliary data
  Accessible without login Plain text file php.xml Data Auxiliary data
  Accessible without login Plain text file php8.iml Data Auxiliary data
  Accessible without login Plain text file vcs.xml Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:199
This week:1
All time:8,492
This week:35Up