Help Needed Preparing a Lecture About Past, Present and Future of OOP in PHP

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
fifothekid
New php-forum User
New php-forum User
Posts: 1
Joined: Mon Jan 22, 2018 7:35 am

Mon Jan 22, 2018 7:37 am

Hi everybody
I'm preparing a lecture about the object-oriented programming features in PHP. This lecture is inspired by my recent experience in PHP 7.0 try to create a complicated registration system requiring all the 4 pillars of OOP (Abstraction, Encapsulation, Inheritance and Polymorphism).
Since I've been mostly languages like C++ and C# in the past 10 years, I was shocked that many OOP features that we take for granted are simply not available in PHP 7!
For example, this would give an error message PHP 7:

Code: Select all

public function returnStringOrNull( array $optionalArray = null) : string
{
    if ($optionalArray) {
        return implode(', ', $optionalArray);
    }
    return null;
}
and the solution for it in PHP 7 is:

Code: Select all

public function returnStringOrNull( array $optionalArray = null) : string
{
    if ($optionalArray) {
        return implode(', ', $optionalArray);
    }
    return '';
}
While in PHP 7.1 you can do it something like this (using nullable return types):

Code: Select all

function nullOrString(int $foo) : ?string
{
    return $foo%2 ? "odd" : null;
}
So I'm trying to create a short lecture that talks about the progress made in OOP features in PHP made so far and what are the alternative solutions for some missing features.
I'm currently trying to extract as much data from the official documentations and from the book PHP Objects, Patterns, and Practice.

If you have any suggestions regarding resources talking about the history of OOP in PHP, or, any method of comparing OOP implementations between different languages I'd be really grateful.

Post Reply