|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #4025 unable to use $this when calling array_walk from a class method.
Submitted: 2000-04-04 04:59 UTC Modified: 2001-09-09 09:31 UTC
From: php at tsquires dot demon dot co dot uk Assigned:
Status: Not a bug Package: Misbehaving function
PHP Version: 3.0.15 OS: Linux RH6.1 / WinNT4
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.
Block user comment
Status: Assign to:
Bug Type:
From: php at tsquires dot demon dot co dot uk
New email:
PHP Version: OS:


 [2000-04-04 04:59 UTC] php at tsquires dot demon dot co dot uk
I would like to do something like this: 

class example { 
function print_a_list ( $an_array ) 

function do_something { 
array_walk( fruits, "$this->print_a_list" ); 

The error returned is 
Warning: Unable to call () - function does not exist in inc\example_class.php 

To get it working I have done this 

class example { 

function do_something { 
    define('PRINT_FUNCTION', TRUE); 
    function print_a_list ( $an_array ) 
  array_walk( fruits, "print_a_list" ); 
} //end do_something 
} //end example class 

The define is to stop errors when I call the do_something method more than once for a single instance of the example class. If I don't it gives me a Cannot Redelare error. 
This is not really perfect becasue I have to declare print_a_list twice if I want to use it outside the do_something function.  Plus the code is abit messy. 

I've asked and studied the docs but I can find a way around it.  I've also tried it using php4 with the same results.
Thanks for your time,


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-09-09 09:31 UTC]
not a bug, ask php support questions on
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Oct 25 14:01:23 2020 UTC