[wp-trac] [WordPress Trac] #43455: apply_filters not passing by ref

WordPress Trac noreply at wordpress.org
Thu Mar 1 21:11:51 UTC 2018


#43455: apply_filters not passing by ref
--------------------------+-----------------------------
 Reporter:  lordspace     |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  4.8
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Hey folks,

 I've tried passing some extra params to a filter by reference and it
 doesn't seem to work via apply_filters. Do you know why?

 {{{#!php
 <?php
 $arr = [
         'name' => 'slavi',
     ];

     $arr2 = [
         'total' => 0,
     ];

     $obj = new stdClass();
     $obj->total = 0;

     $arr = apply_filters('test', $arr, $arr2, $obj);

     add_filter('test', 'orb_pp_by_ref', 20, 3);

     function orb_pp_by_ref($arr, & $arr2, & $obj)
     {
         $arr2['total'] += 10;
         $obj->total += 10;
         return $arr;
     }

     echo "<pre>";

     echo '$arr:';
     var_dump($arr);

     echo '$arr2:';
     var_dump($arr2);

     echo '$obj:';
     var_dump($obj);

     echo "Direct call<br/>";

     orb_pp_by_ref($arr, $arr2, $obj);
     echo '$arr:';
     var_dump($arr);

     echo '$arr2:';
     var_dump($arr2);

     echo '$obj:';
     var_dump($obj);

     echo "</pre>";
 }}}


 Result:

 {{{
 $arr:array(1) {
   ["name"]=>
   string(5) "slavi"
 }
 $arr2:array(1) {
   ["total"]=>
   int(0)
 }
 $obj:object(stdClass)#408 (1) {
   ["total"]=>
   int(0)
 }
 Direct call
 $arr:array(1) {
   ["name"]=>
   string(5) "slavi"
 }
 $arr2:array(1) {
   ["total"]=>
   int(10)
 }
 $obj:object(stdClass)#408 (1) {
   ["total"]=>
   int(10)
 }
 }}}


 version.php

 {{{#!php
 <?php
 /**
  * The WordPress version string
  *
  * @global string $wp_version
  */
 $wp_version = '4.8.5';

 /**
  * Holds the WordPress DB revision, increments when changes are made to
 the WordPress DB schema.
  *
  * @global int $wp_db_version
  */
 $wp_db_version = 38590;

 /**
  * Holds the TinyMCE version
  *
  * @global string $tinymce_version
  */
 $tinymce_version = '4603-20170530';

 /**
  * Holds the required PHP version
  *
  * @global string $required_php_version
  */
 $required_php_version = '5.2.4';

 /**
  * Holds the required MySQL version
  *
  * @global string $required_mysql_version
  */
 $required_mysql_version = '5.0';

 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/43455>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list