function.runkit-sandbox-output-handler.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 146 行
HTML
146 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Specify a function to capture and/or process output from a runkit sandbox</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.runkit-return-value-used.html">runkit_return_value_used</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.runkit-superglobals.html">runkit_superglobals</a></div> <div class="up"><a href="ref.runkit.html">runkit Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.runkit-sandbox-output-handler" class="refentry"> <div class="refnamediv"> <h1 class="refname">runkit_sandbox_output_handler</h1> <p class="verinfo">(PECL runkit:0.7-0.9)</p><p class="refpurpose"><span class="refname">runkit_sandbox_output_handler</span> — <span class="dc-title"> Specify a function to capture and/or process output from a runkit sandbox </span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><b><b>runkit_sandbox_output_handler</b></b></span> ( <span class="methodparam"><span class="type">object</span> <tt class="parameter">$sandbox</tt></span> [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$callback</tt></span> ] )</div> <p class="para rdfs-comment"> Ordinarily, anything output (such as with <a href="function.echo.html" class="function">echo()</a> or <a href="function.print.html" class="function">print()</a>) will be output as though it were printed from the parent's scope. Using <b>runkit_sandbox_output_handler()</b> however, output generated by the sandbox (including errors), can be captured by a function outside of the sandbox. </p> <blockquote><p><b class="note">Note</b>: <span class="simpara">Sandbox support (required for<a href="function.runkit-lint.html" class="function">runkit_lint()</a>, <a href="function.runkit-lint-file.html" class="function">runkit_lint_file()</a>,and the <b class="classname">Runkit_Sandbox</b> class) is only available as ofPHP 5.1.0 or specially patched versions of PHP 5.0, and requires that threadsafety be enabled.See the <var class="filename">README</var> file included in the runkit package formore information.</span></p></blockquote> <blockquote><p><b class="note">Note</b>: <b>Deprecated</b><br /> As of runkit version 0.5, this function is deprecated and is scheduled to be removed from the package prior to a 1.0 release. The output handler for a given Runkit_Sandbox instance may be read/set using the array offset syntax shown on the <a href="runkit.sandbox.html" class="link">Runkit_Sandbox</a> class definition page. <br /> </p></blockquote> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">sandbox</tt></i></span> <dd> <p class="para"> Object instance of Runkit_Sandbox class on which to set output handling. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">callback</tt></i></span> <dd> <p class="para"> Name of a function which expects one parameter. Output generated by <i><tt class="parameter">sandbox</tt></i> will be passed to this callback. Anything returned by the callback will be displayed normally. If this parameter is not passed then output handling will not be changed. If a non-truth value is passed, output handling will be disabled and will revert to direct display. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the name of the previously defined output handler callback, or <b><tt>FALSE</tt></b> if no handler was previously defined. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 Feeding output to a variable</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">capture_output</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$GLOBALS</span><span style="color: #007700">[</span><span style="color: #DD0000">'sandbox_output'</span><span style="color: #007700">] .= </span><span style="color: #0000BB">$str</span><span style="color: #007700">;<br /><br /> return </span><span style="color: #DD0000">''</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$sandbox_output </span><span style="color: #007700">= </span><span style="color: #DD0000">''</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$php </span><span style="color: #007700">= new </span><span style="color: #0000BB">Runkit_Sandbox</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">runkit_sandbox_output_handler</span><span style="color: #007700">(</span><span style="color: #0000BB">$php</span><span style="color: #007700">, </span><span style="color: #DD0000">'capture_output'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">-></span><span style="color: #0000BB">echo</span><span style="color: #007700">(</span><span style="color: #DD0000">"Hello\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">-></span><span style="color: #0000BB">eval</span><span style="color: #007700">(</span><span style="color: #DD0000">'var_dump("Excuse me");'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">-></span><span style="color: #0000BB">die</span><span style="color: #007700">(</span><span style="color: #DD0000">"I lost myself."</span><span style="color: #007700">);<br />unset(</span><span style="color: #0000BB">$php</span><span style="color: #007700">);<br /><br />echo </span><span style="color: #DD0000">"Sandbox Complete\n\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">$sandbox_output</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents"><pre><div class="cdata"><pre>Sandbox CompleteHellostring(9) "Excuse me"I lost myself.</pre></div> </pre></div> </div> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.runkit-return-value-used.html">runkit_return_value_used</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.runkit-superglobals.html">runkit_superglobals</a></div> <div class="up"><a href="ref.runkit.html">runkit Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?