Professional Web Applications Themes

#24286 [Com]: using array from class as function name - PHP Development

ID: 24286 Comment by: bloso at mailbr dot com dot br Reported By: terjeto at stud dot ntnu dot no Status: Verified Bug Type: Zend Engine 2 problem Operating System: RedHat 9.0 PHP Version: 5CVS-2003-06-22 (dev) New Comment: I've got the same error message: Fatal error: Method name must be a string in /var/www/htdocs/scorphus/phplab/countracker/tpl/templates_c/%%200/%%2001463753/index.html.php on line 28 index.html.php line 28: <br><?php echo $this->_plugins['function']['eval'][0](array('var' => $this->_config[0]['vars']['credits']), $this) ; ?> PHP Version: 5.0.0b2-dev (php5-200307071930.tar.gz) Configure Command: './configure' '--with-mysql' '--with-apxs' System: Slackware 9 (2.4.20) and Debian 3.0 r1 (2.4.20) Also unsing: Smarty 2.4.2 Hope it helps, Pablo. Previous Comments: ------------------------------------------------------------------------ [2003-06-29 10:55:12] [email]iliaaphp.net[/email] ...

  1. #1

    Default #24286 [Com]: using array from class as function name

    ID: 24286
    Comment by: bloso at mailbr dot com dot br
    Reported By: terjeto at stud dot ntnu dot no
    Status: Verified
    Bug Type: Zend Engine 2 problem
    Operating System: RedHat 9.0
    PHP Version: 5CVS-2003-06-22 (dev)
    New Comment:

    I've got the same error message:

    Fatal error: Method name must be a string in
    /var/www/htdocs/scorphus/phplab/countracker/tpl/templates_c/%%200/%%2001463753/index.html.php
    on line 28

    index.html.php line 28:
    <br><?php echo $this->_plugins['function']['eval'][0](array('var' =>
    $this->_config[0]['vars']['credits']), $this) ; ?>

    PHP Version: 5.0.0b2-dev (php5-200307071930.tar.gz)
    Configure Command: './configure' '--with-mysql' '--with-apxs'
    System: Slackware 9 (2.4.20) and Debian 3.0 r1 (2.4.20)
    Also unsing: Smarty 2.4.2

    Hope it helps,
    Pablo.


    Previous Comments:
    ------------------------------------------------------------------------

    [2003-06-29 10:55:12] [email]iliaaphp.net[/email]

    Works fine in php 4.3.3, so this appears to be a BC issue.

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

    [2003-06-22 10:54:07] terjeto at stud dot ntnu dot no

    Description:
    ------------
    When using a string from an array inside an class for
    calling a function it results in a fatal error.

    Reproduce code:
    ---------------
    <?php

    class Foo {
    var $_array = array( 'function' => array ( 'spacer' => array( 0 =>
    '_funk' ) ) );
    }

    function _funk( $arg ) {
    print( $arg );
    }

    $_out = array( 'function' => array ( 'spacer' => array( 0 => '_funk' )
    ) );

    _funk( "Test string 1<br>" );

    $foo = new Foo();

    $foofunk = $foo->_array['function']['spacer'][0];

    $foofunk( "Test string 2<br>" );

    $_out['function']['spacer'][0]( "Test string 3<br>" );
    $foo->_array['function']['spacer'][0]( "Test string 4<br>" );
    ?>

    Expected result:
    ----------------
    Test string 1
    Test string 2
    Test string 3
    Test string 4

    Actual result:
    --------------
    Test string 1
    Test string 2
    Test string 3

    Fatal error: Method name must be a string in /var/
    www/html/test.php on line 22


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


    --
    Edit this bug report at [url]http://bugs.php.net/?id=24286&edit=1[/url]

    bloso at mailbr dot com dot br Guest

  2. #2

    Default #24286 [Com]: using array from class as function name

    ID: 24286
    Comment by: tony2001 at phpclub dot net
    Reported By: terjeto at stud dot ntnu dot no
    Status: Verified
    Bug Type: Zend Engine 2 problem
    Operating System: RedHat 9.0
    PHP Version: 5CVS-2003-06-22 (dev)
    New Comment:

    There is no matter what Smarty version do you use.
    PHP complains on this syntax:
    <?
    class Test {
    var $array_var = Array();
    function test() {
    $this->array_var[0][0][0] = "test_method";
    }
    function test_method($echo_var) {
    echo $echo_var;
    }
    }

    $test_obj = new test;
    $test_obj->array_var[0][0][0]("simple test"); //line 15
    ?>
    Fatal error: Method name must be a string in /www/index.php on line 15

    Guys, please, fix this very annoying bug at least in beta2.
    On 10 Jul 2003 this bug still exists in CVS.


    Previous Comments:
    ------------------------------------------------------------------------

    [2003-07-09 08:09:13] bloso at mailbr dot com dot br

    I've got the same error message:

    Fatal error: Method name must be a string in
    /var/www/htdocs/scorphus/phplab/countracker/tpl/templates_c/%%200/%%2001463753/index.html.php
    on line 28

    index.html.php line 28:
    <br><?php echo $this->_plugins['function']['eval'][0](array('var' =>
    $this->_config[0]['vars']['credits']), $this) ; ?>

    PHP Version: 5.0.0b2-dev (php5-200307071930.tar.gz)
    Configure Command: './configure' '--with-mysql' '--with-apxs'
    System: Slackware 9 (2.4.20) and Debian 3.0 r1 (2.4.20)
    Also unsing: Smarty 2.4.2

    Hope it helps,
    Pablo.

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

    [2003-06-29 10:55:12] [email]iliaaphp.net[/email]

    Works fine in php 4.3.3, so this appears to be a BC issue.

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

    [2003-06-22 10:54:07] terjeto at stud dot ntnu dot no

    Description:
    ------------
    When using a string from an array inside an class for
    calling a function it results in a fatal error.

    Reproduce code:
    ---------------
    <?php

    class Foo {
    var $_array = array( 'function' => array ( 'spacer' => array( 0 =>
    '_funk' ) ) );
    }

    function _funk( $arg ) {
    print( $arg );
    }

    $_out = array( 'function' => array ( 'spacer' => array( 0 => '_funk' )
    ) );

    _funk( "Test string 1<br>" );

    $foo = new Foo();

    $foofunk = $foo->_array['function']['spacer'][0];

    $foofunk( "Test string 2<br>" );

    $_out['function']['spacer'][0]( "Test string 3<br>" );
    $foo->_array['function']['spacer'][0]( "Test string 4<br>" );
    ?>

    Expected result:
    ----------------
    Test string 1
    Test string 2
    Test string 3
    Test string 4

    Actual result:
    --------------
    Test string 1
    Test string 2
    Test string 3

    Fatal error: Method name must be a string in /var/
    www/html/test.php on line 22


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


    --
    Edit this bug report at [url]http://bugs.php.net/?id=24286&edit=1[/url]

    tony2001 at phpclub dot net Guest

  3. #3

    Default #24286 [Com]: using array from class as function name

    ID: 24286
    Comment by: tony2001 at phpclub dot net
    Reported By: terjeto at stud dot ntnu dot no
    Status: Verified
    Bug Type: Zend Engine 2 problem
    Operating System: RedHat 9.0
    PHP Version: 5CVS-2003-06-22 (dev)
    New Comment:

    I expect that using attribute of the object as method name it will work
    as it's already working with PHP4.

    That is:
    $object->attribute = 'method_name';
    and with
    $object->attribute();
    $object->method_name(); should be called.
    Maybe I'm wrong, but in case of $object->obj_attribute->attribute(); we
    have the same situation - we're calling
    $object->obj_attribite->{method, which name contains
    $object->obj_attribute->attribute }();

    Am I wrong?


    Previous Comments:
    ------------------------------------------------------------------------

    [2003-07-10 07:19:37] [email]stasphp.net[/email]

    What is expected to be result of $test_obj->array_var[0][0][0]("simple
    test") call?

    Which function or method of which object should be called? What with
    $test_obj->foo->array_var[0][0][0]("simple test") - should the calling
    object be $test_obj and function name array_var[0][0][0] (should it be
    global $array_var[0][0][0]? global $foo->array_var[0][0][0]? or
    property foo->array_var[0][0][0] of $test_obj?) or the calling object
    should be $test_obj->foo and array_var[0][0][0] should be the method
    name?

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

    [2003-07-10 06:25:06] tony2001 at phpclub dot net

    There is no matter what Smarty version do you use.
    PHP complains on this syntax:
    <?
    class Test {
    var $array_var = Array();
    function test() {
    $this->array_var[0][0][0] = "test_method";
    }
    function test_method($echo_var) {
    echo $echo_var;
    }
    }

    $test_obj = new test;
    $test_obj->array_var[0][0][0]("simple test"); //line 15
    ?>
    Fatal error: Method name must be a string in /www/index.php on line 15

    Guys, please, fix this very annoying bug at least in beta2.
    On 10 Jul 2003 this bug still exists in CVS.

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

    [2003-07-09 08:09:13] bloso at mailbr dot com dot br

    I've got the same error message:

    Fatal error: Method name must be a string in
    /var/www/htdocs/scorphus/phplab/countracker/tpl/templates_c/%%200/%%2001463753/index.html.php
    on line 28

    index.html.php line 28:
    <br><?php echo $this->_plugins['function']['eval'][0](array('var' =>
    $this->_config[0]['vars']['credits']), $this) ; ?>

    PHP Version: 5.0.0b2-dev (php5-200307071930.tar.gz)
    Configure Command: './configure' '--with-mysql' '--with-apxs'
    System: Slackware 9 (2.4.20) and Debian 3.0 r1 (2.4.20)
    Also unsing: Smarty 2.4.2

    Hope it helps,
    Pablo.

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

    [2003-06-29 10:55:12] [email]iliaaphp.net[/email]

    Works fine in php 4.3.3, so this appears to be a BC issue.

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

    [2003-06-22 10:54:07] terjeto at stud dot ntnu dot no

    Description:
    ------------
    When using a string from an array inside an class for
    calling a function it results in a fatal error.

    Reproduce code:
    ---------------
    <?php

    class Foo {
    var $_array = array( 'function' => array ( 'spacer' => array( 0 =>
    '_funk' ) ) );
    }

    function _funk( $arg ) {
    print( $arg );
    }

    $_out = array( 'function' => array ( 'spacer' => array( 0 => '_funk' )
    ) );

    _funk( "Test string 1<br>" );

    $foo = new Foo();

    $foofunk = $foo->_array['function']['spacer'][0];

    $foofunk( "Test string 2<br>" );

    $_out['function']['spacer'][0]( "Test string 3<br>" );
    $foo->_array['function']['spacer'][0]( "Test string 4<br>" );
    ?>

    Expected result:
    ----------------
    Test string 1
    Test string 2
    Test string 3
    Test string 4

    Actual result:
    --------------
    Test string 1
    Test string 2
    Test string 3

    Fatal error: Method name must be a string in /var/
    www/html/test.php on line 22


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


    --
    Edit this bug report at [url]http://bugs.php.net/?id=24286&edit=1[/url]

    tony2001 at phpclub dot net Guest

  4. #4

    Default #24286 [Com]: using array from class as function name

    ID: 24286
    Comment by: tony2001 at phpclub dot net
    Reported By: terjeto at stud dot ntnu dot no
    Status: Verified
    Bug Type: Zend Engine 2 problem
    Operating System: RedHat 9.0
    PHP Version: 5CVS-2003-06-22 (dev)
    New Comment:

    ok, here is some workaround on this problem:
    in case of
    <?
    class Test {
    var $var = Array('test_function');
    function test_function($echo_var) {
    echo $echo_var;
    }
    }

    $test_obj = new test;
    $test_obj->var[0]('bla');
    ?>
    you can avoid Fatal error in last string using this instead:
    <?
    $test_obj->{$test_obj->var[0]}('bla');
    ?>

    But in case of:
    <?
    class Test {
    var $var = Array('test_function');
    }

    function test_function($echo_var) {
    echo $echo_var;
    }
    ?>
    (i.e. you need to call a function, not a method, which name is
    contained in objects, attribute) it seems, that there is no way, but
    use this temporary variable:
    <?
    $test_obj = new test;
    $tmp = $test_obj->var[0];
    $tmp('bla');
    ?>

    And another one important info:
    in CVS version of Smarty this trouble is already solved.


    Previous Comments:
    ------------------------------------------------------------------------

    [2003-07-29 15:38:17] tony2001 at phpclub dot net

    Maybe you're right. But this syntax works as I expect with PHP4 and I
    suppose this is a BC problem.
    I really do not know how implementation of this syntax in ZE2 differs
    from ZE1, but I expected it to continue to work in the same way. My
    apologies if I was wrong.

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

    [2003-07-27 07:13:03] [email]stasphp.net[/email]

    Why with "$object->attribute()"
    "$object->method_name()" should be called and not
    "$object->attribute()" and how the engine is supposed to tell that? Is
    $foo->x() now meaning "call method 'x' of object '$foo'" or "take
    property 'x' of object '$foo' and call method with this name on object
    '$foo'"? My opinion is that it _always_ should mean the latter and
    never the former.

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

    [2003-07-10 07:57:44] tony2001 at phpclub dot net

    I expect that using attribute of the object as method name it will work
    as it's already working with PHP4.

    That is:
    $object->attribute = 'method_name';
    and with
    $object->attribute();
    $object->method_name(); should be called.
    Maybe I'm wrong, but in case of $object->obj_attribute->attribute(); we
    have the same situation - we're calling
    $object->obj_attribite->{method, which name contains
    $object->obj_attribute->attribute }();

    Am I wrong?

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

    [2003-07-10 07:19:37] [email]stasphp.net[/email]

    What is expected to be result of $test_obj->array_var[0][0][0]("simple
    test") call?

    Which function or method of which object should be called? What with
    $test_obj->foo->array_var[0][0][0]("simple test") - should the calling
    object be $test_obj and function name array_var[0][0][0] (should it be
    global $array_var[0][0][0]? global $foo->array_var[0][0][0]? or
    property foo->array_var[0][0][0] of $test_obj?) or the calling object
    should be $test_obj->foo and array_var[0][0][0] should be the method
    name?

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

    [2003-07-10 06:25:06] tony2001 at phpclub dot net

    There is no matter what Smarty version do you use.
    PHP complains on this syntax:
    <?
    class Test {
    var $array_var = Array();
    function test() {
    $this->array_var[0][0][0] = "test_method";
    }
    function test_method($echo_var) {
    echo $echo_var;
    }
    }

    $test_obj = new test;
    $test_obj->array_var[0][0][0]("simple test"); //line 15
    ?>
    Fatal error: Method name must be a string in /www/index.php on line 15

    Guys, please, fix this very annoying bug at least in beta2.
    On 10 Jul 2003 this bug still exists in CVS.

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

    The remainder of the comments for this report are too long. To view
    the rest of the comments, please view the bug report online at
    [url]http://bugs.php.net/24286[/url]

    --
    Edit this bug report at [url]http://bugs.php.net/?id=24286&edit=1[/url]

    tony2001 at phpclub dot net Guest

Similar Threads

  1. Replies: 3
    Last Post: March 19th, 07:59 PM
  2. Subclassing Array Class
    By Ramin in forum Macromedia Flash
    Replies: 0
    Last Post: November 25th, 03:30 AM
  3. How do I call an outer function from a class method function?
    By Phil Powell in forum PHP Development
    Replies: 5
    Last Post: October 16th, 09:56 AM
  4. Replies: 2
    Last Post: August 18th, 09:18 AM
  5. #24286 [Ver]: using array from class as function name
    By stas@php.net in forum PHP Development
    Replies: 0
    Last Post: July 27th, 12:13 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139