Skip to content

Fix GH-3336: String arguments that are converted have misleading explanation #3337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion language-snippets.ent
Original file line number Diff line number Diff line change
Expand Up @@ -2182,7 +2182,12 @@ or an explicit call to <function>chr</function> should be made.</para></warning>

<!-- GMP Notes -->
<!ENTITY gmp.return 'A <classname xmlns="http://docbook.org/ns/docbook">GMP</classname> object.'>
<!ENTITY gmp.parameter '<para xmlns="http://docbook.org/ns/docbook">A <classname>GMP</classname> object, an &integer; or a numeric &string;.</para>'>
<!ENTITY gmp.parameter '<para xmlns="http://docbook.org/ns/docbook">
A <classname>GMP</classname> object, an &integer;,
or a &string; that can be interpreted as a number following the same logic
as if the string was used in <function>gmp_init</function> with automatic
base detection (i.e. when <parameter>base</parameter> is equal to 0).
</para>'>

<!-- MySQLi Notes -->
<!ENTITY mysqli.result.description '<varlistentry xmlns="http://docbook.org/ns/docbook"><term>
Expand Down
97 changes: 66 additions & 31 deletions reference/gmp/functions/gmp-init.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,47 @@

<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>num</parameter></term>
<listitem>
<para>
An integer or a string. The string representation can be decimal,
hexadecimal or octal.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>base</parameter></term>
<listitem>
<para>
The base.
</para>
<para>
The base may vary from 2 to 62. If base is 0 (default value), the
actual base is determined from the leading characters: if the first
two characters are <literal>0x</literal> or <literal>0X</literal>,
hexadecimal is assumed, if the first two characters are <literal>0b</literal> or <literal>0B</literal>,
binary is assumed, otherwise if the first character is <literal>0</literal>,
octal is assumed, otherwise decimal is assumed.
For bases up to 36, case is ignored; upper-case and lower-case letters have the same value.
For bases 37 to 62, upper-case letter represent the usual 10 to 35 while lower-case letter represent 36 to 61.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<variablelist>
<varlistentry>
<term><parameter>num</parameter></term>
<listitem>
<simpara>
An integer or a string. The string representation can be decimal,
hexadecimal, octal, or binary.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>base</parameter></term>
<listitem>
<simpara>
The base to use for converting a <type>string</type> representation.
</simpara>
<simpara>
An explicit base can be between <literal>2</literal> and <literal>62</literal>.
For bases up to <literal>36</literal>, case is ignored;
upper-case and lower-case letters have the same value.
For bases <literal>37</literal> to <literal>62</literal>,
upper-case letter represent the values <literal>10</literal> to
<literal>35</literal> and lower-case letter represent the values
<literal>36</literal> to <literal>61</literal>.
</simpara>
<simpara>
If <parameter>base</parameter> is <literal>0</literal> then the actual
base is determined from the leading characters of <parameter>num</parameter>.
If the first two characters are <literal>0x</literal> or <literal>0X</literal>,
the string is interpreted as a hexadecimal integer.
If the first two characters are <literal>0b</literal> or <literal>0B</literal>,
the string is interpreted as a binary integer.
If the first two characters are <literal>0o</literal> or <literal>0o</literal>,
the string is interpreted as an octal integer.
Moreover, if the first character is <literal>0</literal> the string
is also interpreted as an octal integer.
In all other cases, the string is interpreted as a decimal integer.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

<refsect1 role="returnvalues">
Expand All @@ -60,6 +70,31 @@
</para>
</refsect1>

<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.1.0</entry>
<entry>
Support for explicit octal prefixes <literal>0o</literal> and
<literal>0o</literal> has been added for <parameter>num</parameter> strings.
Interpretation of such prefixes when <parameter>base</parameter> is
<literal>0</literal> has also been added.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<para>
Expand Down
62 changes: 4 additions & 58 deletions reference/gmp/gmp/construct.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<refentry xml:id="gmp.construct" xmlns="http://docbook.org/ns/docbook">
<refentry xml:id="gmp.construct" xmlns="http://docbook.org/ns/docbook" xmlns:xi="http://www.w3.org/2001/XInclude">
<refnamediv>
<refname>GMP::__construct</refname>
<refpurpose>Create GMP number</refpurpose>
Expand All @@ -18,64 +18,10 @@
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>num</parameter></term>
<listitem>
<para>
An integer or a string. The string representation can be decimal,
hexadecimal or octal.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>base</parameter></term>
<listitem>
<para>
The base.
</para>
<para>
The base may vary from 2 to 62. If base is 0 (default value), the
actual base is determined from the leading characters: if the first
two characters are <literal>0x</literal> or <literal>0X</literal>,
hexadecimal is assumed, if the first two characters are <literal>0b</literal> or <literal>0B</literal>,
binary is assumed, otherwise if the first character is <literal>0</literal>,
octal is assumed, otherwise decimal is assumed.
For bases up to 36, case is ignored; upper-case and lower-case letters have the same value.
For bases 37 to 62, upper-case letter represent the usual 10 to 35 while lower-case letter represent 36 to 61.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>

<!--
<refsect1 role="examples">
&reftitle.examples;
<example xml:id="gmp.construct.example.basic">
<title><methodname>GMP::__construct</methodname> example</title>
<para>
Description.
</para>
<programlisting role="php">
<![CDATA[
<?php
echo "Code example";
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Code example
]]>
</screen>
</example>
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('function.gmp-init')/db:refsect1[@role='parameters']/*)">
<xi:fallback/>
</xi:include>
</refsect1>
-->

<refsect1 role="seealso">
&reftitle.seealso;
Expand Down