runkit.sandbox-parent.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 143 行
HTML
143 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Runkit Anti-Sandbox Class</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="runkit.sandbox.html">Runkit_Sandbox</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.runkit-class-adopt.html">runkit_class_adopt</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="runkit.sandbox-parent" class="refentry"> <div class="refnamediv"> <h1 class="refname">Runkit_Sandbox_Parent</h1> <p class="verinfo">(No version information available, might be only in CVS)</p><p class="refpurpose"><span class="refname">Runkit_Sandbox_Parent</span> — <span class="dc-title"> Runkit Anti-Sandbox Class </span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><span class="type void">void</span></span> <span class="methodname"><b><b>Runkit_Sandbox_Parent::__construct</b></b></span> ( <span class="methodparam">void</span> )</div> <p class="para rdfs-comment"> Instantiating the <b class="classname">Runkit_Sandbox_Parent</b> class from within a sandbox environment created from the <b class="classname">Runkit_Sandbox</b> class provides some (controlled) means for a sandbox child to access its parent. </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> <p class="para"> In order for any of the <b class="classname">Runkit_Sandbox_Parent</b> features to function. Support must be enabled on a per-sandbox basis by enabling the <i>parent_access</i> flag from the parent's context. </p> <div class="example"> <p><b>Example #1 Working with variables in a sandbox</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$sandbox </span><span style="color: #007700">= new </span><span style="color: #0000BB">Runkit_Sandbox</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$sandbox</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_access'</span><span style="color: #007700">] = </span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </div> <div class="refsect1 variables"> <h3 class="title">Accessing the Parent's Variables</h3> <p class="para"> Just as with sandbox variable access, a sandbox parent's variables may be read from and written to as properties of the <b class="classname">Runkit_Sandbox_Parent</b> class. Read access to parental variables may be enabled with the <i>parent_read</i> setting (in addition to the base <i>parent_access</i> setting). Write access, in turn, is enabled through the <i>parent_write</i> setting. </p> <p class="para"> Unlike sandbox child variable access, the variable scope is not limited to globals only. By setting the <i>parent_scope</i> setting to an appropriate integer value, other scopes in the active call stack may be inspected instead. A value of 0 (Default) will direct variable access at the global scope. 1 will point variable access at whatever variable scope was active at the time the current block of sandbox code was executed. Higher values progress back through the functions that called the functions that led to the sandbox executing code that tried to access its own parent's variables. </p> <div class="example"> <p><b>Example #2 Accessing parental variables</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$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">$php</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_access'</span><span style="color: #007700">] = </span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_read'</span><span style="color: #007700">] = </span><span style="color: #0000BB">true</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$test </span><span style="color: #007700">= </span><span style="color: #DD0000">"Global"</span><span style="color: #007700">;<br /><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">'$PARENT = new Runkit_Sandbox_Parent;'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_scope'</span><span style="color: #007700">] = </span><span style="color: #0000BB">0</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">one</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_scope'</span><span style="color: #007700">] = </span><span style="color: #0000BB">1</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">one</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_scope'</span><span style="color: #007700">] = </span><span style="color: #0000BB">2</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">one</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_scope'</span><span style="color: #007700">] = </span><span style="color: #0000BB">3</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">one</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_scope'</span><span style="color: #007700">] = </span><span style="color: #0000BB">4</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">one</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$php</span><span style="color: #007700">[</span><span style="color: #DD0000">'parent_scope'</span><span style="color: #007700">] = </span><span style="color: #0000BB">5</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">one</span><span style="color: #007700">();<br /><br />function </span><span style="color: #0000BB">one</span><span style="color: #007700">() {<br /> </span><span style="color: #0000BB">$test </span><span style="color: #007700">= </span><span style="color: #DD0000">"one()"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">two</span><span style="color: #007700">();<br />}<br /><br />function </span><span style="color: #0000BB">two</span><span style="color: #007700">() {<br /> </span><span style="color: #0000BB">$test </span><span style="color: #007700">= </span><span style="color: #DD0000">"two()"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">three</span><span style="color: #007700">();<br />}<br /><br />function </span><span style="color: #0000BB">three</span><span style="color: #007700">() {<br /> </span><span style="color: #0000BB">$test </span><span style="color: #007700">= </span><span style="color: #DD0000">"three()"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$GLOBALS</span><span style="color: #007700">[</span><span style="color: #DD0000">'php'</span><span style="color: #007700">]-></span><span style="color: #0000BB">eval</span><span style="color: #007700">(</span><span style="color: #DD0000">'var_dump($PARENT->test);'</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> <p class="para">The above example will output:</p> <div class="example-contents"><pre><div class="cdata"><pre>string(6) "Global"string(7) "three()"string(5) "two()"string(5) "one()"string(6) "Global"string(6) "Global"</pre></div> </pre></div> </div> <div class="refsect1 functions"> <h3 class="title">Calling the Parent's Functions</h3> <p class="para"> Just as with sandbox access, a sandbox may access its parents functions providing that the proper settings have been enabled. Enabling <i>parent_call</i> will allow the sandbox to call all functions available to the parent scope. Language constructs are each controlled by their own setting: <a href="function.print.html" class="function">print()</a> and <a href="function.echo.html" class="function">echo()</a> are enabled with <i>parent_echo</i>. <a href="function.die.html" class="function">die()</a> and <a href="function.exit.html" class="function">exit()</a> are enabled with <i>parent_die</i>. <a href="function.eval.html" class="function">eval()</a> is enabled with <i>parent_eval</i> while <b>include()</b>, <b>include_once()</b>, <b>require()</b>, and <b>require_once()</b> are enabled through <i>parent_include</i>. </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="runkit.sandbox.html">Runkit_Sandbox</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.runkit-class-adopt.html">runkit_class_adopt</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 + -
显示快捷键?