PHP Classes

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

Recommend this page to a friend!
  Info   View files Example   View files View files (15)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 196 All time: 8,514 This week: 123Up
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: 321 Up14 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  
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  /  .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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:196
This week:0
All time:8,514
This week:123Up