Logic Money->format( $format = null )
and Money->format_i18n( $format = null )
confusing?
#2
Labels
Money->format( $format = null )
and Money->format_i18n( $format = null )
confusing?
#2
In both functions the
$format
parameter is optional, but the parameter doesn't work the same way. Ifnull
is passed inMoney->format_i18n( $format = null )
function it will fall back toMoney::get_default_format()
:wp-money/src/Money.php
Lines 71 to 73 in 86b41ad
If
null
is passed inMoney->format( $format = null )
function it will fall back to'%2$s'
:wp-money/src/Money.php
Lines 127 to 129 in 86b41ad
Currently it's very imported that
Money->format( $format = null )
falls back to'%2$s'
, otherwise some of the gateways will break:pronamic/wp-pronamic-pay-mollie@08bc30c
However, it is not very logical that the
Money->format( $format = null )
does not process currency information by default, without currency information it's just a number.We could make this more clear like this:
Money->format_amount( $number_decimals = null );
, if$number_decimals
isnull
we can fall back to the currency$number_decimals
value, similarly ani18n
version:$money->format_i18n_amount( $number_decimals );
.Naming can also be different:
Money->number_format( $number_decimals = null )
Money->amount_format( $number_decimals = null )
Money->number_format_i18n( $number_decimals = null )
Money->amount_format_i18n( $number_decimals = null )
I think i prefer
number_format
andnumber_format_i18n
:The default format for
Money->format( $format = null )
can then be changed to'%3$s%2$s
' so that it contains at least the currency code by default.Maybe we should also consider replacing the
printf
directives with placeholders:Current use is not very clear:
You have no idea what the result is, following is more clear:
@rvdsteege thoughts?
The text was updated successfully, but these errors were encountered: