Req #81599 [Opn->Fbk]: adding the ability of modular import and export just like modern javascript

From: Date: Mon, 08 Nov 2021 13:59:00 +0000
Subject: Req #81599 [Opn->Fbk]: adding the ability of modular import and export just like modern javascript
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237607@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81599&edit=1

 ID:                 81599
 Updated by:         requinix@php.net
 Reported by:        pooyaestakhry at gmail dot com
 Summary:            adding the ability of modular import and export just
                     like modern javascript
-Status:             Open
+Status:             Feedback
 Type:               Feature/Change Request
 Package:            *General Issues
 Operating System:   All
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

You can already do this.

<?php // strings.func.php

$Module = get_class(new class {
    public function whatami() {
        echo "This is Module\n";
    }
});

$otherModule = function() use ($Module) {
    return new $Module();
};

return [
    "Module" => $Module,
    "otherModule" => $otherModule
];

?>

and

<?php

list["Module" => $Module, "otherModule" => $otherModule] = require
"strings.func.php";

$otherModule()->whatami();

?>

But why would you want to, given that PHP is architecturally, technically, and philosophically
completely different from Javascript?


Previous Comments:
------------------------------------------------------------------------
[2021-11-08 13:09:41] pooyaestakhry at gmail dot com

Description:
------------
PHP is mostly known as a procedural/OOP language.adding the ability to import and export modules
like functions, variables and constants would mean that doors of functional programming would open
up to those us who love php but are not a fan of oop.

Test script:
---------------
import {Module,otherModule as other} from dirname(__dir__,1).'/strings.func.php'



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=81599&edit=1


Thread (10 messages)

« previous php.bugs (#237607) next »