Make WordPress Core

Ticket #9886: apply_filters_ref_array.test.php

File apply_filters_ref_array.test.php, 670 bytes (added by scribu, 15 years ago)
Line 
1<?php
2/*
3Plugin name: apply_filters_ref_array tests
4Author: scribu
5Version: 1.0
6*/
7
8// No additional arguments
9function test_func_simple($value) {
10        return 'pass';
11}
12add_filter('test_filter_simple', 'test_func_simple');
13
14$new_val = apply_filters_ref_array('test_filter_simple', array('fail'));
15var_dump('pass' == $new_val);
16
17// An object reference as an additional argument
18function test_func($value, $arg) {
19        $arg->test = 'pass';
20
21        return 'pass';
22}
23add_filter('test_filter', 'test_func', 10, 2);
24
25$obj = new stdClass();
26$obj->test = 'fail';
27
28$new_val = apply_filters_ref_array('test_filter', array('fail', &$obj));
29var_dump('pass' == $new_val && 'pass' == $obj->test);
30