Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Test
- {
- public function index( )
- {
- $arr = array(
- array('a' => 'aap', 'n' => 'noot', 'm' => 'mies'),
- array('a' => 'ding', 'b' => 'flof', 'c' => 'bips'),
- array( 'd' => 'do', 'e' => 're', 'c' => 'mi')
- );
- $func = array( $this, '_user_func' );
- foreach ($arr as $key => &$value) {
- //$this->_do_callback($func, $value, $key); // No exception but array not modified afterwards
- $param = array(&$value);
- call_user_func( $func, $param, $key ); // Exception: Parameter 1 to TestRef::user_func() expected to be a reference, value given
- }
- unset($value);
- var_dump($arr);
- }
- private function _do_callback( $func, array &$row, $row_id )
- {
- if ( is_callable( $func ) )
- {
- return call_user_func( $func, $row, $row_id );
- }
- else
- {
- throw new Exception( "Error doing callback. Callback empty or not a callable function." );
- }
- }
- private function _user_func( $_arr, $index )
- {
- $arr = &$_arr[0];
- foreach ($arr as $key => $value) {
- $arr[$key] = 'replaced';
- }
- //var_dump($arr); // Works!
- }
- }
- $test = new Test;
- $test->index();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement