[wp-trac] [WordPress Trac] #35781: Incorrect use of PHP method compact
WordPress Trac
noreply at wordpress.org
Sat Feb 27 23:16:18 UTC 2016
#35781: Incorrect use of PHP method compact
-----------------------------------+-----------------------------
Reporter: maweder | Owner: SergeyBiryukov
Type: defect (bug) | Status: closed
Priority: normal | Milestone: 4.4.3
Component: Mail | Version: 4.4
Severity: normal | Resolution: fixed
Keywords: has-patch fixed-major | Focuses:
-----------------------------------+-----------------------------
Changes (by dd32):
* keywords: has-patch fixed-major needs-unit-tests => has-patch fixed-
major
* status: reopened => closed
* resolution: => fixed
Comment:
Not to sound like a broken record, but the current code in trunk is
correct.
{{{
$to = 'to at example.com';
$from = 'from at example.com';
$headers = array( 'Header', 'Two Header' );
$Header = 'Should not appear';
var_dump( compact( 'to', 'from', 'headers' ) );
}}}
will result in :
{{{
array (size=3)
'to' => string 'to at example.com' (length=14)
'from' => string 'from at example.com' (length=16)
'headers' =>
array (size=2)
0 => string 'Header' (length=6)
1 => string 'Two Header' (length=10)
}}}
Whereas {{{var_dump( compact( 'to', 'from', $headers ) );}}} would result
in:
{{{
array (size=3)
'to' => string 'to at example.com' (length=14)
'from' => string 'from at example.com' (length=16)
'Header' => string 'Should not appear' (length=17)
}}}
The array handling in `compact()` is to pass an array of variable names,
when the variable you want in the output is itself a array it should be
specified as a string.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/35781#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list