On Thu, Dec 17, 2009 at 01:27, Philip Olson <[email protected]> wrote:
>
> On Dec 15, 2009, at 2:43 AM, Daniel Egeberg wrote:
>
>> I have attached patches to bugs #50311 and #50317. I also cleaned up
>> the strrpos() page while I was at it seeing as #50317 is about that
>> function.
>
> Hello Daniel,
>
> And now for some nitpicking:
>
> #50317
> It's preferred to use the changelog role instead of <notes> for changes.
> Granted this manual page already uses <note> for this, but since you're
> updating it then it may as well use the newer syntax. It's sibling strrchr()
> uses the changelog role, so it should help you see how it's done.
I see. Thanks.
> #50311
> Although you copied the format from the current manual, it's also something
> we do in places (but shouldn't). :) And that's writing 'you' within the
> manual.
Ah yeah, I actually think I read that somewhere. Can't remember
exactly where though.
> Maybe something more like "intval() should not be used on objects, as doing
> so will emit an E_NOTICE level error and return 1." although I wonder if
> that's always true. Seems to be:
>
> <?php
> $a = new DomDocument();
> $b = intval($a);
> var_dump($b);
> ?>
>
> Notice: Object of class DOMDocument could not be converted to int
> int(1)
>
> What do you think?
I haven't been able to find an object I could successfully cast to
integer. It's probably safe to assume it's always the case.
>> I had been thinking about getting more involved in the PHP project
>> lately. Seeing as my C skills aren't too sharp I figured I'd start
>> with the documentation. Should I just apply for an SVN account now, or
>> should I keep sending in patches?
>
> I think you should apply for a SVN account, after you update your patches to
> cleanup the current docs.
Okay. I've applied for one now and attached updated patches in case
you want to review them again. Thanks for your feedback. Might as well
get it right first time.
--
Daniel Egeberg
Index: reference/strings/functions/strrpos.xml
===================================================================
--- reference/strings/functions/strrpos.xml (revision 292149)
+++ reference/strings/functions/strrpos.xml (working copy)
@@ -22,52 +22,6 @@
as the needle, then only the first character of that string will
be used.
</para>
- <para>
- If <parameter>needle</parameter> is not found, returns &false;.
- </para>
- <para>
- It is easy to mistake the return values for "character found at
- position 0" and "character not found". Here's how to detect
- the difference:
- <informalexample>
- <programlisting role="php">
-<![CDATA[
-<?php
-
-// in PHP 4.0.0 and newer:
-$pos = strrpos($mystring, "b");
-if ($pos === false) { // note: three equal signs
- // not found...
-}
-
-// in versions older than 4.0.0:
-$pos = strrpos($mystring, "b");
-if (is_bool($pos) && !$pos) {
- // not found...
-}
-?>
-]]>
- </programlisting>
- </informalexample>
- </para>
- <para>
- If <parameter>needle</parameter> is not a string, it is converted
- to an integer and applied as the ordinal value of a character.
- </para>
- <note>
- <simpara>
- As of PHP 5.0.0 <parameter>offset</parameter> may
- be specified to begin searching an arbitrary number of characters into
- the string. Negative values will stop searching at an arbitrary point
- prior to the end of the string.
- </simpara>
- </note>
- <note>
- <simpara>
- The <parameter>needle</parameter> may be a string of more than one
- character as of PHP 5.0.0.
- </simpara>
- </note>
</refsect1>
<refsect1 role="parameters">
@@ -78,6 +32,7 @@
<term><parameter>haystack</parameter></term>
<listitem>
<para>
+ The string to search in.
</para>
</listitem>
</varlistentry>
@@ -85,6 +40,8 @@
<term><parameter>needle</parameter></term>
<listitem>
<para>
+ If <parameter>needle</parameter> is not a string, it is converted
+ to an integer and applied as the ordinal value of a character.
</para>
</listitem>
</varlistentry>
@@ -92,6 +49,9 @@
<term><parameter>offset</parameter></term>
<listitem>
<para>
+ May be specified to begin searching an arbitrary number of characters into
+ the string. Negative values will stop searching at an arbitrary point
+ prior to the end of the string.
</para>
</listitem>
</varlistentry>
@@ -102,10 +62,94 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
-
+ Returns the position where the needle exists. Returns &false; if the needle
+ was not found.
</para>
</refsect1>
+
+ <refsect1 role="changelog">
+ &reftitle.changelog;
+ <para>
+ <informaltable>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>&Version;</entry>
+ <entry>&Description;</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>5.0.0</entry>
+ <entry>
+ The <parameter>needle</parameter> may now be a string of more than one
+ character.
+ </entry>
+ </row>
+ <row>
+ <entry>5.0.0</entry>
+ <entry>
+ The <parameter>offset</parameter> parameter was introduced.
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+ </refsect1>
+
+ <refsect1 role="examples">
+ &reftitle.examples;
+ <para>
+ <example>
+ <title>Checking if a needle is in the haystack</title>
+ <para>
+ It is easy to mistake the return values for "character found at
+ position 0" and "character not found". Here's how to detect
+ the difference:
+ </para>
+ <programlisting role="php">
+<![CDATA[
+<?php
+// in PHP 4.0.0 and newer:
+$pos = strrpos($mystring, "b");
+if ($pos === false) { // note: three equal signs
+ // not found...
+}
+
+// in versions older than 4.0.0:
+$pos = strrpos($mystring, "b");
+if (is_bool($pos) && !$pos) {
+ // not found...
+}
+?>
+]]>
+ </programlisting>
+ </example>
+ </para>
+ <para>
+ <example>
+ <title>Searching with offsets</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$foo = "0123456789a123456789b123456789c";
+
+var_dump(strrpos($foo, '7', -5)); // Starts looking backwards five positions
+ // from the end. Result: int(17)
+
+var_dump(strrpos($foo, '7', 20)); // Starts searching 20 positions into the
+ // string. Result: int(27)
+
+var_dump(strrpos($foo, '7', 28)); // Result: bool(false)
+?>
+]]>
+ </programlisting>
+ </example>
+ </para>
+ </refsect1>
+
<refsect1 role="seealso">
&reftitle.seealso;
<para>
Index: reference/var/functions/intval.xml
===================================================================
--- reference/var/functions/intval.xml (revision 292149)
+++ reference/var/functions/intval.xml (working copy)
@@ -16,7 +16,8 @@
<para>
Returns the <type>integer</type> value of <parameter>var</parameter>,
using the specified <parameter>base</parameter> for the conversion
- (the default is base 10).
+ (the default is base 10). <function>intval</function> should not be used
+ on objects, as doing so will emit an E_NOTICE level error and return 1.
</para>
</refsect1>
@@ -92,6 +93,8 @@
echo intval('420000000000000000000'); // 2147483647
echo intval(42, 8); // 42
echo intval('42', 8); // 34
+echo intval(array()); // 0
+echo intval(array('foo', 'bar')); // 1
?>
]]>
</programlisting>
Index: reference/var/functions/floatval.xml
===================================================================
--- reference/var/functions/floatval.xml (revision 292149)
+++ reference/var/functions/floatval.xml (working copy)
@@ -23,8 +23,8 @@
<term><parameter>var</parameter></term>
<listitem>
<para>
- May be any scalar type. You cannot use <function>floatval</function>
- on arrays or objects.
+ May be any scalar type. <function>floatval</function> should not be used
+ on objects, as doing so will emit an E_NOTICE level error and return 1.
</para>
</listitem>
</varlistentry>
@@ -34,7 +34,8 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
- The float value of the given variable.
+ The float value of the given variable. Empty arrays return 0, non-empty
+ arrays return 1.
</para>
</refsect1>
<refsect1 role="examples">