mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-27 14:28:56 +00:00

- PHP 3 development appendix moved to this part - Streams API docs moved to this part - ZendAPI docs with figures integrated in this part More info: http://news.php.net/php.doc/969369673 git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@194089 c90b9560-bf6c-de11-be94-00142212c4b1
193 lines
8.1 KiB
XML
193 lines
8.1 KiB
XML
<?xml version="1.0" encoding="ISO-8859-1" ?>
|
|
<!-- $Revision: 1.1 $ -->
|
|
<sect1 id="zend.printing">
|
|
<title>Printing Information</title>
|
|
<para>
|
|
Often it's necessary to print messages to the output stream from
|
|
your module, just as <function>print</function> would be used
|
|
within a script. PHP offers functions for most generic tasks, such
|
|
as printing warning messages, generating output for
|
|
<function>phpinfo</function>, and so on. The following sections
|
|
provide more details. Examples of these functions can be found on
|
|
the CD-ROM.
|
|
</para>
|
|
<sect2 id="zend.printing.zend-printf">
|
|
<title><function>zend_printf</function></title>
|
|
<para>
|
|
<function>zend_printf</function> works like the
|
|
standard <function>printf</function>, except that it prints to Zend's
|
|
output stream.
|
|
</para>
|
|
</sect2>
|
|
|
|
<sect2 id="zend.printing.zend-error">
|
|
<title><function>zend_error</function></title>
|
|
<para>
|
|
<function>zend_error</function> can be used to generate error messages.
|
|
This function accepts two arguments; the first is the error type (see
|
|
<filename>zend_errors.h</filename>), and the second is the error message.
|
|
<programlisting>zend_error(E_WARNING, "This function has been called with empty arguments");</programlisting><xref linkend='tab.error-messages'/> shows a list of possible values (see <xref linkend='fig.warning-messages'/>). These
|
|
values are also referred to in <filename>php.ini</filename>. Depending on
|
|
which error type you choose, your messages will be logged.
|
|
<table id='tab.error-messages'>
|
|
<title>Zend's Predefined Error Messages.</title>
|
|
<tgroup cols="2">
|
|
<colspec colnum="1" colname="col1" colwidth="1.00*"/>
|
|
<colspec colnum="2" colname="col2" colwidth="1.36*"/>
|
|
<tbody>
|
|
<row>
|
|
<entry colname="col1">Error</entry>
|
|
<entry colname="col2">Description</entry>
|
|
</row>
|
|
<row>
|
|
<entry colname="col1"><literal>E_ERROR</literal></entry>
|
|
<entry colname="col2">
|
|
Signals an error and terminates execution of the script
|
|
immediately
|
|
.</entry>
|
|
</row>
|
|
<row>
|
|
<entry colname="col1"><literal>E_WARNING</literal></entry>
|
|
<entry colname="col2">
|
|
Signals a generic warning. Execution continues.
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry colname="col1"><literal>E_PARSE</literal></entry>
|
|
<entry colname="col2">
|
|
Signals a parser error. Execution continues.
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry colname="col1"><literal>E_NOTICE</literal></entry>
|
|
<entry colname="col2">
|
|
Signals a notice. Execution continues. Note that by
|
|
default the display of this type of error messages is turned off in
|
|
<filename>php.ini</filename>.
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry colname="col1"><literal>E_CORE_ERROR</literal></entry>
|
|
<entry colname="col2">
|
|
Internal error by the core; shouldn't be used by
|
|
user-written modules.
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry colname="col1"><literal>E_COMPILE_ERROR</literal></entry>
|
|
<entry colname="col2">
|
|
Internal error by the compiler; shouldn't be used by
|
|
user-written modules.
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry colname="col1"><literal>E_COMPILE_WARNING</literal></entry>
|
|
<entry colname="col2">
|
|
Internal warning by the compiler; shouldn't be used by
|
|
user-written modules.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</table>
|
|
<figure id='fig.warning-messages'>
|
|
<title>Display of warning messages in the browser.</title>
|
|
<graphic fileref="figures/zend.07-warning-messages.png"/>
|
|
</figure></para>
|
|
</sect2>
|
|
|
|
<sect2 id="zend.printing.phpinfo">
|
|
<title>Including Output in <function>phpinfo</function></title>
|
|
<para>
|
|
After creating a real module, you'll want to show information
|
|
about the module in <function>phpinfo</function> (in addition to the
|
|
module name, which appears in the module list by default). PHP allows
|
|
you to create your own section in the <function>phpinfo</function> output with the <literal>ZEND_MINFO()</literal> function. This function
|
|
should be placed in the module descriptor block (discussed earlier) and is
|
|
always called whenever a script calls <function>phpinfo</function>.
|
|
</para>
|
|
<para>
|
|
PHP automatically prints a section
|
|
in <function>phpinfo</function> for you if you specify the <literal>ZEND_MINFO</literal>
|
|
function, including the module name in the heading. Everything else must be
|
|
formatted and printed by you.
|
|
</para>
|
|
<para>
|
|
Typically, you can print an HTML table header
|
|
using <function>php_info_print_table_start</function> and then use the standard
|
|
functions <function>php_info_print_table_header</function>
|
|
and <function>php_info_print_table_row</function>. As arguments, both take the number of
|
|
columns (as integers) and the column contents (as strings). <xref linkend='example.phpinfo'/> shows a source example and its output. To print the table footer, use <function>php_info_print_table_end</function>.
|
|
</para>
|
|
<example id='example.phpinfo'>
|
|
<title>
|
|
Source code and screenshot for output in <function>phpinfo</function>.
|
|
</title>
|
|
<programlisting>
|
|
php_info_print_table_start();
|
|
php_info_print_table_header(2, "First column", "Second column");
|
|
php_info_print_table_row(2, "Entry in first row", "Another entry");
|
|
php_info_print_table_row(2, "Just to fill", "another row here");
|
|
php_info_print_table_end();
|
|
</programlisting>
|
|
<graphic fileref="figures/zend.08-phpinfo-output.png"/>
|
|
</example>
|
|
</sect2>
|
|
|
|
<sect2 id="zend.printing.execution">
|
|
<title>Execution Information</title>
|
|
<para>
|
|
You can also print execution information, such as the current file
|
|
being executed. The name of the function currently being executed
|
|
can be retrieved using the function
|
|
<function>get_active_function_name</function>. This function
|
|
returns a pointer to the function name and doesn't accept any
|
|
arguments. To retrieve the name of the file currently being
|
|
executed, use <function>zend_get_executed_filename</function>.
|
|
This function accesses the executor globals, which are passed to
|
|
it using the <literal>TSRMLS_C</literal> macro. The executor globals
|
|
are automatically available to every function that's called
|
|
directly by Zend (they're part of the
|
|
<literal>INTERNAL_FUNCTION_PARAMETERS</literal> described earlier
|
|
in this chapter). If you want to access the executor globals in
|
|
another function that doesn't have them available automatically,
|
|
call the macro <literal>TSRMLS_FETCH()</literal> once in that
|
|
function; this will introduce them to your local scope.
|
|
</para>
|
|
<para>
|
|
Finally, the line number currently being executed can be retrieved
|
|
using the function <function>zend_get_executed_lineno</function>.
|
|
This function also requires the executor globals as arguments. For
|
|
examples of these functions, see <xref linkend='example.exec-info'/>.
|
|
</para>
|
|
<example id='example.exec-info'>
|
|
<title>Printing execution information.</title>
|
|
<programlisting>
|
|
zend_printf("The name of the current function is %s<br>", get_active_function_name(TSRMLS_C));
|
|
zend_printf("The file currently executed is %s<br>", zend_get_executed_filename(TSRMLS_C));
|
|
zend_printf("The current line being executed is %i<br>", zend_get_executed_lineno(TSRMLS_C));
|
|
</programlisting>
|
|
<graphic fileref="figures/zend.09-execution-info.png"/>
|
|
</example>
|
|
</sect2>
|
|
</sect1>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|