[wp-trac] [WordPress Trac] #35781: Incorrect use of PHP method compact
WordPress Trac
noreply at wordpress.org
Sun Feb 28 15:11:48 UTC 2016
#35781: Incorrect use of PHP method compact
------------------------------------------+-----------------------------
Reporter: maweder | Owner: SergeyBiryukov
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: 4.4.3
Component: Mail | Version: 4.4
Severity: normal | Resolution:
Keywords: fixed-major needs-unit-tests | Focuses:
------------------------------------------+-----------------------------
Comment (by maweder):
My mistake. '''You're right.'''
Replying to [comment:12 dd32]:
> 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:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list