php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #45863 Variable functions.
Submitted: 2008-08-19 10:28 UTC Modified: 2014-11-02 01:33 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: amethana at gmail dot com Assigned: requinix (profile)
Status: Closed Package: *General Issues
PHP Version: 5.2.6 OS: Irrelevant
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: amethana at gmail dot com
New email:
PHP Version: OS:

 

 [2008-08-19 10:28 UTC] amethana at gmail dot com
Description:
------------
Variable functions would be nice.

Especially seeing that this works:

class Test {function mb_strlen($v){return mb_strlen($v);}}
$type = 'mb_str';
$obj = new Test;
echo $obj->{$type . "len"}($type);

Reproduce code:
---------------
$type = 'mb_str';

echo {$type . 'len'}($type);

Expected result:
----------------
6

Actual result:
--------------
Parse error: syntax error, unexpected '{' in Command line code on line 1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-10-12 20:17 UTC] klaussantana at gmail dot com
Look at this:

<?php
echo call_user_func('mb_strlen', $type);
echo call_user_func_array('mb_strlen', array($type));
?>

You can also do something like this:

<?php
function MyBrandNewFunction( $Param1, $Param2, $Param3 ){}
echo call_user_func('MyBrandNewFunction', $Param1, $Param2, $Param3);
echo call_user_func_array('MyBrandNewFunction', array( $Param1, $Param2, $Param3 ));
?>

But working like that would be nice too.
 [2014-11-02 01:33 UTC] requinix@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: requinix
 [2014-11-02 01:33 UTC] requinix@php.net
Supported in PHP 7.
http://3v4l.org/mGOCD
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 00:01:34 2025 UTC