mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Improve resource functions examples (#1435)
This commit is contained in:
parent
498bb30063
commit
77887dc8e5
3 changed files with 23 additions and 12 deletions
reference/var/functions
|
@ -51,24 +51,23 @@
|
|||
&reftitle.examples;
|
||||
<para>
|
||||
<example>
|
||||
<title><function>get_resource_id</function> example</title>
|
||||
<title><function>get_resource_id</function> produces the same result as an <type>int</type> cast</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$handle = fopen('./storage/logs/lumen.log', 'rt');
|
||||
$handle = fopen("php://stdout", "w");
|
||||
|
||||
echo (int) $handle . "\n\n";
|
||||
echo (int) $handle . "\n";
|
||||
|
||||
echo get_resource_id($handle);
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
&example.outputs.similar;
|
||||
<screen role="php">
|
||||
<![CDATA[
|
||||
698
|
||||
|
||||
698
|
||||
]]>
|
||||
</screen>
|
||||
|
|
|
@ -58,16 +58,22 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
// prints: stream
|
||||
$fp = fopen("foo", "w");
|
||||
echo get_resource_type($fp) . "\n";
|
||||
|
||||
// prints: curl
|
||||
$c = curl_init ();
|
||||
echo get_resource_type($c) . "\n"; // works prior to PHP 8.0.0 as since 8.0 curl_init returns a CurlHandle object
|
||||
// As of PHP 8.0.0, the following does not work anymore. The curl_init function returns a CurlHandle object now.
|
||||
$c = curl_init();
|
||||
echo get_resource_type($c) . "\n";
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs.7;
|
||||
<screen role="php">
|
||||
<![CDATA[
|
||||
stream
|
||||
curl
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
|
|
@ -53,14 +53,20 @@
|
|||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$db_link = @mysql_connect('localhost', 'mysql_user', 'mysql_pass');
|
||||
if (!is_resource($db_link)) {
|
||||
die('Can\'t connect : ' . mysql_error());
|
||||
$handle = fopen("php://stdout", "w");
|
||||
if (is_resource($handle)) {
|
||||
echo '$handle is a resource';
|
||||
}
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs;
|
||||
<screen role="php">
|
||||
<![CDATA[
|
||||
$handle is a resource
|
||||
]]>
|
||||
</screen>
|
||||
</example>
|
||||
</para>
|
||||
</refsect1>
|
||||
|
|
Loading…
Reference in a new issue