<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Runkit Anti-Sandbox Class</title> </head> <body><div class="manualnavbar" 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">(PECL runkit >= 0.7.0)</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" id="refsect1-runkit.sandbox-parent-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type"><span class="type void">void</span></span> <span class="methodname"><strong>Runkit_Sandbox_Parent::__construct</strong></span> ( <span class="methodparam">void</span> )</div> <p class="para rdfs-comment"> Instantiating the <strong class="classname">Runkit_Sandbox_Parent</strong> class from within a sandbox environment created from the <strong class="classname">Runkit_Sandbox</strong> class provides some (controlled) means for a sandbox child to access its parent. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">Sandbox support (required for <span class="function"><a href="function.runkit-lint.html" class="function">runkit_lint()</a></span>, <span class="function"><a href="function.runkit-lint-file.html" class="function">runkit_lint_file()</a></span>, and the <strong class="classname">Runkit_Sandbox</strong> class) is only available as of PHP 5.1.0 or specially patched versions of PHP 5.0, and requires that thread safety be enabled. See the <var class="filename">README</var> file included in the runkit package for more information.</span></p></blockquote> <p class="para"> In order for any of the <strong class="classname">Runkit_Sandbox_Parent</strong> features to function. Support must be enabled on a per-sandbox basis by enabling the <em>parent_access</em> flag from the parent's context. </p> <div class="example" id="example-532"> <p><strong>Example #1 Working with variables in a sandbox</strong></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" id="refsect1-runkit.sandbox-parent-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 <strong class="classname">Runkit_Sandbox_Parent</strong> class. Read access to parental variables may be enabled with the <em>parent_read</em> setting (in addition to the base <em>parent_access</em> setting). Write access, in turn, is enabled through the <em>parent_write</em> setting. </p> <p class="para"> Unlike sandbox child variable access, the variable scope is not limited to globals only. By setting the <em>parent_scope</em> 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" id="example-533"> <p><strong>Example #2 Accessing parental variables</strong></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 screen"> <div class="cdata"><pre> string(6) "Global" string(7) "three()" string(5) "two()" string(5) "one()" string(6) "Global" string(6) "Global" </pre></div> </div> </div> <div class="refsect1 functions" id="refsect1-runkit.sandbox-parent-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 <em>parent_call</em> will allow the sandbox to call all functions available to the parent scope. Language constructs are each controlled by their own setting: <span class="function"><a href="function.print.html" class="function">print</a></span> and <span class="function"><a href="function.echo.html" class="function">echo</a></span> are enabled with <em>parent_echo</em>. <span class="function"><a href="function.die.html" class="function">die()</a></span> and <span class="function"><a href="function.exit.html" class="function">exit()</a></span> are enabled with <em>parent_die</em>. <span class="function"><a href="function.eval.html" class="function">eval()</a></span> is enabled with <em>parent_eval</em> while <span class="function"><a href="function.include.html" class="function">include</a></span>, <span class="function"><a href="function.include-once.html" class="function">include_once</a></span>, <span class="function"><a href="function.require.html" class="function">require</a></span>, and <span class="function"><a href="function.require-once.html" class="function">require_once</a></span> are enabled through <em>parent_include</em>. </p> </div> </div><hr /><div class="manualnavbar" 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>