php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63020 Dynamic functions & methods unification
Submitted: 2012-09-05 20:21 UTC Modified: 2017-10-17 12:27 UTC
From: p dot szymkowski at gmail dot com Assigned:
Status: Suspended Package: Scripting Engine problem
PHP Version: 5.4.6 OS: Any
Private report: No CVE-ID: None
 [2012-09-05 20:21 UTC] p dot szymkowski at gmail dot com
Description:
------------
This is more than a feature than a bug.

Usage of '{}' is not unified at all.

Why this syntax:
$this->{'function'}; 
works, but:
{'function'}();
doesn't?

It's really confusing. In "test script" form i am giving you full example of it.

Test script:
---------------
<?php

function myFunction(){};

// {'myFunction'}(); // doesn't work
$str = 'myFunction';
$str(); // works

class myClass {
  public $bar = 'myClass';
  public $test = 'myClass';
  public function foo() {
  }
}

// $class = new {'myClass'}(); // doesn't work
$str = "myClass";
$class = new $str(); // works

$class->{'foo'}(); // works

// $class2 = new {$class->test}; // doesn't work
$class2 = new $class->test(); // works

Expected result:
----------------
syntax {'myFunction'}(); should work
syntax $class = new {'myClass'}(); should work
syntax $class2 = new {$class->test}; should work

Actual result:
--------------
only calling methods and getting properties of class works in that way.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-06 01:35 UTC] aharvey@php.net
I'd be surprised if we didn't have bugs/requests for this already, but I can't find them at a glance, so let's leave this open in the right package.

The AST RFC might be of interest here, since it would presumably provide a path towards fixing this: https://wiki.php.net/rfc/ast_based_parsing_compilation_process
 [2012-09-06 01:35 UTC] aharvey@php.net
-Package: Documentation problem +Package: Scripting Engine problem
 [2017-10-17 12:27 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2017-10-17 12:27 UTC] cmb@php.net
Thank you for your interest in PHP and for submitting a feature request. Please
be aware that due to the magnitude of change this request requires, it would be
necessary to discuss it on PHP Internals list (internals@lists.php.net) as an
RFC. Please read the guide about creating RFCs here:
<https://wiki.php.net/rfc/howto>. If you haven't had experience with writing
RFCs before, it is advised to seek guidance on the Internals list
(<http://php.net/mailing-lists.php>) and/or solicit help from one of the
experienced developers. 

Please do not consider this comment as a negative view on the merits of your
proposal – every proposal which requires changes of certain magnitude, even the
very successful and widely supported ones, must be done through the RFC process.
This helps make the process predictable, transparent and accessible to all
developers.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC