php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #80722 Missing support for Dependency Inversion Principle and for serving the purpose
Submitted: 2021-02-07 11:01 UTC Modified: 2021-02-08 13:03 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: fakhar_anwar123 at hotmail dot com Assigned:
Status: Suspended Package: *Extensibility Functions
PHP Version: 8.0.2 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: fakhar_anwar123 at hotmail dot com
New email:
PHP Version: OS:

 

 [2021-02-07 11:01 UTC] fakhar_anwar123 at hotmail dot com
Description:
------------
---
From manual page: https://php.net/language.oop5.interfaces
---
We do not have Interface variables in PHP, which means the client-side code (consumer) can not point to abstraction. That means PHP does not  adheres to A) Dependency Inversion Principle (DIP) and B) it also does not serve the actual purpose behind Interface Segregation Principle ('I' in S.O.L.I.D).

Those are two powerful techniques for extensibility with flexibility.

Can you please add support to that syntax like through a separate module in Swoole ?

As example please See P-13 and P-15 in that blog
https://www.codeproject.com/Articles/18743/Interfaces-in-C-For-Beginners

Test script:
---------------
N/A


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-02-07 11:24 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2021-02-07 11:24 UTC] requinix@php.net
Your description doesn't agree with the P13 and P15 examples in that link so I don't know why you're linking to it.

There is nothing stopping you from implementing whatever design patterns you would like in PHP other than an unnecessary insistence upon a particular syntax or code style.
 [2021-02-07 11:36 UTC] fakhar_anwar123 at hotmail dot com
The "Interface Segregation Principle (ISP)" is to about ability to break-down larger interface into smaller interfaces, its purpose is to expose, to the Consumers, different subsets of the (functions) of a Serving-entity (Class), in the form of small Packages / Deals (aka Interfaces) 

(...while hiding the Mechanism; details of how those Services are produced, internally, by the Serving-entity)

Consumers (Client-side code) can then consume needed subset/s of services (of the Serving Entity; Class) in the form of Packages / Deals (Interfaces). 

Benefit / Purpose:
The Serving-end can extend services of a Package (Interface), if needed, without effecting other Packages (Interfaces) which means without effecting the Consumers consuming those Packages (Interfaces).

This is a powerful technique for extending the offerings with flexibility.

Example:
See P-15 and P-13 on the link below to understand the purpose of Interface Segregation Principle in OOD/OOP.
https://www.codeproject.com/Articles/18743/Interfaces-in-C-For-Beginners

PHP8.0 must allow declaration of Interface variables to conform to the core priniples of development like Interface Segregation Principle (ISP) and Dependency Inversion Principle (DIP).
 [2021-02-07 11:38 UTC] rtrtrtrtrt at dfdfdfdf dot dfd35
> PHP8.0 must allow declaration of.....

no, an already released version MUST NOT allow or change anything in behavior which wasn't a bug
 [2021-02-07 11:47 UTC] fakhar_anwar123 at hotmail dot com
I put up this issue not as "Bug" but as a key feature (as it is a key feature of Object-oriented Design / Programming).

So, we conclude that PHP upto its latest version 8.02 does not comply with the core Principles of Software Engineering (or, their actual purpose), namely
A) Dependency Inversion Principle DIP), and 
B) Interface Segregation Principle (ISP).
 [2021-02-07 11:50 UTC] rtrtrtrtrt at dfdfdfdf dot dfd35
> as it is a key feature of Object-oriented Design / Programming

i wonder how we surivived the past 20 years
 [2021-02-07 11:53 UTC] requinix@php.net
Once again, PHP is perfectly capable of whatever design patterns you like, but expecting PHP to support the same syntax you've seen in other languages will not work.
 [2021-02-07 12:11 UTC] fakhar_anwar123 at hotmail dot com
Again, i am not looking for a Design Patter, but support for a core Design Principle which all Object-oriented languages enable through the use of Interface. 

I am myself a PHP user, with 15 years experience. I have remained a strong advocator of PHP and PHP Frameworks. However, it is very disppointing to see the response of a represntative of PHP Community that instead of promising the support for this very basic and needful feature, you are adopting to be defensive and asking questions like "How PHP survived". I can provide you a beneiftting answer to it, please do no understimate me.

The question today is "Why other technologies like NodeJS and Go dented the market of PHP in past few years", but i do not want to go into that detail.

Please, tell me when Interface variables are not supported ? When PHP will start adhering to the CORE PRINCIPLES (not design patterns) of Software Engineering?
A) Dependency Inversion Principle
B) (purpose behind) Interface Segregation Principle
 [2021-02-07 12:16 UTC] rtrtrtrtrt at dfdfdfdf dot dfd35
> response of a represntative of PHP Community

i am not, i am a user

how did you come to the conclusion that "rtrtrtrtrt@dfdfdfdf.dfd35" is a "represntative of PHP Community"?

> be defensive and asking questions like "How PHP survived"

i just pointed out that what you call "core principles" others don't care and you wasn't able to back your position by anything other than your opinion
 [2021-02-07 12:23 UTC] fakhar_anwar123 at hotmail dot com
Ahh okay so are a user, i assumed you are a C++ developer behind PHP.

My brother i have submitted a strong case along with proper references. But the speed of your respnse clearly shows that you are in haste and not reading thoroughly. 

When we ask for support of a feature, it should be taken as a support for the platform (PHP), not criticism.


I am an architect with 20 years experience in Object-oriente Design, and a critical analytical researcher, technology analyst.
 [2021-02-07 12:27 UTC] fakhar_anwar123 at hotmail dot com
Refined Concept: Uptil PHP8.0, PHP does not support "Interface Variables" which allows to comply with two core Principles of Software Development
A) Dependency Inversion Principle DIP, and
B) Interface Segregation Principle (ISP)
(These are principles

Why Interface Variables Are Need Feature:
The "Interface Segregation Principle (ISP)" is not just about breaking down larger interface into smaller interfaces, its actual purpose is to expose/offer (to the Consumers client-class code) different subsets of the functions of a Serving-entity (Class), in the form of small Packages / Deals (aka Interfaces)

(...hiding the Mechanism; details of how those Services are produced, internally, by the Serving-entity)

Consumers (Client-side code) can then consume needed subset/s of functions/services of the Serving Entity; Class in the form of packages / deals (Interfaces).

Benefit / Purpose:
The Serving-end can extend services of a package (Interface), if needed, without effecting other exposed Packages (Interfaces) which means without effecting the Consumers consuming those packages (Interfaces).

Example:
See P-15 and P-13 for better understanding.
https://www.codeproject.com/Articles/18743/Interfaces-in-C-For-Beginners
 [2021-02-07 12:29 UTC] rtrtrtrtrt at dfdfdfdf dot dfd35
> When we ask for support of a feature, 
> it should be taken as a support for the 
> platform (PHP), not criticism

for the sake of god: https://wiki.php.net/rfc/howto
 [2021-02-07 12:43 UTC] requinix@php.net
-Status: Not a bug +Status: Suspended
 [2021-02-07 12:49 UTC] fakhar_anwar123 at hotmail dot com
Thanks for providing the link to the guidelines to RFC Process.

what i conclude from the second paragraph in that is that if i do not code a PHP feature myself using C++ (or, no one choose to develop that feature), then highlighted feature would not become the part PHP. 

Based on that premise, I hope someone look into the required feature which i am highlighting here. 

If you can do that i will be happy, if not then at least encourage to get the support of that feature to make PHP stronger platform. (Be eralistic and do not shelter what is missing, lets be realistic). 

Lets do it, before others highlight this very basic feature as mising in PHP.
 [2021-02-08 13:03 UTC] cmb@php.net
I really don't understand what this feature request is about.  Are
you looking for typed local variables?
 [2021-02-10 18:53 UTC] rowan dot collins at gmail dot com
Firstly, please understand that what you are asking for is not a day's work for someone to add an extra function, it's a complex feature with wide consequences. Understand, too, that unless you're offering to pay, you're asking someone to volunteer that effort. 

Using words like "must" and "key feature" come across as a *demand* for that work; people generally respond better if you can word it as a *suggestion* using words like "could" and "useful". It's also good to spend some time understanding the project, and not making basic mistakes like requesting a feature in 8.0 (already released) rather than 8.1 (where new features will be added to release at the end of this year).

Now, let's try to understand what you're suggesting. Here's what PHP supports regarding interfaces:

* Defining interfaces
* Marking classes as implementing those interfaces
* Checking manually that a particular value implements a required interface (e.g. using instanceof) 
* Checking _automatically_ that a value implements a required interface (by specifying the interface as a parameter, return, or property type)
* Documenting the *intent* of interacting with a particular interface in an easily machine-readable way

The only thing PHP does *not* do is *enforce* the restriction of interacting *only* with the methods guaranteed by the interface. I think that's what you're asking for.

That's because PHP implements something called "duck typing": if you ask an object to perform an action, PHP will just check if the object *can* do it, not whether it "should" according to some contract. This is part of a wider design decision that PHP's type system is "dynamic": the operations available depend at run time on the type of a particular value, rather than being guaranteed at compile time by static information.

That fundamental design is unlikely to change, although features have been added in recent versions making the type system stricter in various ways.

The more checks we add every time the code runs, the slower things will get, so the best time to check if code is using only the methods promised by an interface would be during static analysis. Unlike some dynamic languages (e.g. Python, Hack) PHP doesn't currently have an official static analyser, but there are several very powerful third-party tools that can do these kinds of checks, e.g. Phan, Psalm. IDEs such as PhpStorm also have built-in static analysis which will enforce this for you.

If you are really interested in having more functionality around this in PHP, I recommend learning a bit about how PHP's type system currently works, and what those third-party tools do, and coming up with an approach that you think would make sense for PHP. That doesn't mean you need to develop it by yourself, but the more effort you can put into designing it, the more likely you are to find a volunteer to help you implement it.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Oct 24 01:03:33 2021 UTC