Bug #4025 Updated: unable to use $this when calling array_walk from a class method.

From: Date: Sun, 09 Sep 2001 13:31:00 +0000
Subject: Bug #4025 Updated: unable to use $this when calling array_walk from a class method.
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-65571@lists.php.net to get a copy of this message
ID: 4025
Updated by: sterling
Reported By: php@tsquires.demon.co.uk
Old Status: Open
Status: Bogus
Bug Type: Misbehaving function
Operating System: Linux RH6.1 / WinNT4
PHP Version: 3.0.15
New Comment:

not a bug, ask php support questions on
php-general@lists.php.net

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

[2000-04-04 04:59:00] php@tsquires.demon.co.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 { 
{ 
  if(!defined('PRINT_FUNCTION')) 
  { 
    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 experts-exchange.com 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,
Tim.

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



Edit this bug report at http://bugs.php.net/?id=4025&edit=1



Thread (1 message)

  • sterling@php.net
  • Unknown Message
    • sterling@php.net
« previous php.dev (#65571) next »