<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >Runkit_Sandbox_Parent</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="runkit Functions" HREF="ref.runkit.html"><LINK REL="PREVIOUS" TITLE="Runkit_Sandbox" HREF="runkit.sandbox.html"><LINK REL="NEXT" TITLE="runkit_class_adopt" HREF="function.runkit-class-adopt.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="runkit.sandbox.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.runkit-class-adopt.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="runkit.sandbox-parent" ></A >Runkit_Sandbox_Parent</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN198720" ></A ><P > (no version information, might be only in CVS)</P >Runkit_Sandbox_Parent -- Runkit Anti-Sandbox Class </DIV ><DIV CLASS="refsect1" ><A NAME="AEN198723" ></A ><H2 >说明</H2 >void <B CLASS="methodname" >Runkit_Sandbox_Parent::__construct</B > ( void )<BR ></BR ><P > 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 ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B >对沙盒的支持(是函数 <A HREF="function.runkit-lint.html" ><B CLASS="function" >runkit_lint()</B ></A >、<A HREF="function.runkit-lint-file.html" ><B CLASS="function" >runkit_lint_file()</B ></A > 和 Runkit_Sandbox 类所必须的)仅在 PHP 5.1 中,或在加过特别补丁的 PHP 5.0 中可用,并需要启用线程安全。请阅读 runkit 包中的 README 文件以了解更多信息。 </P ></BLOCKQUOTE ></DIV ><P > 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 <TT CLASS="literal" >parent_access</TT > flag from the parent's context. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN198739" ></A ><P ><B >例 1. Working with variables in a sandbox</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$sandbox </font><font color="#007700">= new </font><font color="#0000BB">Runkit_Sandbox</font><font color="#007700">();<br /></font><font color="#0000BB">$sandbox</font><font color="#007700">[</font><font color="#DD0000">'parent_access'</font><font color="#007700">] = </font><font color="#0000BB">true</font><font color="#007700">;<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN198742" ></A ><H2 >Accessing the Parent's Variables</H2 ><P > 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 <TT CLASS="literal" >parent_read</TT > setting (in addition to the base <TT CLASS="literal" >parent_access</TT > setting). Write access, in turn, is enabled through the <TT CLASS="literal" >parent_write</TT > setting. </P ><P > Unlike sandbox child variable access, the variable scope is not limited to globals only. By setting the <TT CLASS="literal" >parent_scope</TT > 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 ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN198751" ></A ><P ><B >例 2. Accessing parental variables</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$php </font><font color="#007700">= new </font><font color="#0000BB">Runkit_Sandbox</font><font color="#007700">();<br /></font><font color="#0000BB">$php</font><font color="#007700">[</font><font color="#DD0000">'parent_access'</font><font color="#007700">] = </font><font color="#0000BB">true</font><font color="#007700">;<br /></font><font color="#0000BB">$php</font><font color="#007700">[</font><font color="#DD0000">'parent_read'</font><font color="#007700">] = </font><font color="#0000BB">true</font><font color="#007700">;<br /><br /></font><font color="#0000BB">$test </font><font color="#007700">= </font><font color="#DD0000">"Global"</font><font color="#007700">;<br /><br /></font><font color="#0000BB">$php</font><font color="#007700">-></font><font color="#0000BB">eval</font><font color="#007700">(</font><font color="#DD0000">'$PARENT = new Runkit_Sandbox_Parent;'</font><font color="#007700">);<br /><br /></font><font color="#0000BB">$php</font><font color="#007700">[</font><font color="#DD0000">'parent_scope'</font><font color="#007700">] = </font><font color="#0000BB">0</font><font color="#007700">;<br /></font><font color="#0000BB">one</font><font color="#007700">();<br /><br /></font><font color="#0000BB">$php</font><font color="#007700">[</font><font color="#DD0000">'parent_scope'</font><font color="#007700">] = </font><font color="#0000BB">1</font><font color="#007700">;<br /></font><font color="#0000BB">one</font><font color="#007700">();<br /><br /></font><font color="#0000BB">$php</font><font color="#007700">[</font><font color="#DD0000">'parent_scope'</font><font color="#007700">] = </font><font color="#0000BB">2</font><font color="#007700">;<br /></font><font color="#0000BB">one</font><font color="#007700">();<br /><br /></font><font color="#0000BB">$php</font><font color="#007700">[</font><font color="#DD0000">'parent_scope'</font><font color="#007700">] = </font><font color="#0000BB">3</font><font color="#007700">;<br /></font><font color="#0000BB">one</font><font color="#007700">();<br /><br /></font><font color="#0000BB">$php</font><font color="#007700">[</font><font color="#DD0000">'parent_scope'</font><font color="#007700">] = </font><font color="#0000BB">4</font><font color="#007700">;<br /></font><font color="#0000BB">one</font><font color="#007700">();<br /><br /></font><font color="#0000BB">$php</font><font color="#007700">[</font><font color="#DD0000">'parent_scope'</font><font color="#007700">] = </font><font color="#0000BB">5</font><font color="#007700">;<br /></font><font color="#0000BB">one</font><font color="#007700">();<br /><br />function </font><font color="#0000BB">one</font><font color="#007700">() {<br /> </font><font color="#0000BB">$test </font><font color="#007700">= </font><font color="#DD0000">"one()"</font><font color="#007700">;<br /> </font><font color="#0000BB">two</font><font color="#007700">();<br />}<br /><br />function </font><font color="#0000BB">two</font><font color="#007700">() {<br /> </font><font color="#0000BB">$test </font><font color="#007700">= </font><font color="#DD0000">"two()"</font><font color="#007700">;<br /> </font><font color="#0000BB">three</font><font color="#007700">();<br />}<br /><br />function </font><font color="#0000BB">three</font><font color="#007700">() {<br /> </font><font color="#0000BB">$test </font><font color="#007700">= </font><font color="#DD0000">"three()"</font><font color="#007700">;<br /> </font><font color="#0000BB">$GLOBALS</font><font color="#007700">[</font><font color="#DD0000">'php'</font><font color="#007700">]-></font><font color="#0000BB">eval</font><font color="#007700">(</font><font color="#DD0000">'var_dump($PARENT->test);'</font><font color="#007700">);<br />}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ><P >上例将输出:</P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >string(6) "Global" string(7) "three()" string(5) "two()" string(5) "one()" string(6) "Global" string(6) "Global"</PRE ></TD ></TR ></TABLE ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN198756" ></A ><H2 >Calling the Parent's Functions</H2 ><P > Just as with sandbox access, a sandbox may access its parents functions providing that the proper settings have been enabled. Enabling <TT CLASS="literal" >parent_call</TT > 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" ><B CLASS="function" >print()</B ></A > and <A HREF="function.echo.html" ><B CLASS="function" >echo()</B ></A > are enabled with <TT CLASS="literal" >parent_echo</TT >. <A HREF="function.die.html" ><B CLASS="function" >die()</B ></A > and <A HREF="function.exit.html" ><B CLASS="function" >exit()</B ></A > are enabled with <TT CLASS="literal" >parent_die</TT >. <A HREF="function.eval.html" ><B CLASS="function" >eval()</B ></A > is enabled with <TT CLASS="literal" >parent_eval</TT > while <A HREF="function.include.html" ><B CLASS="function" >include()</B ></A >, <A HREF="function.include-once.html" ><B CLASS="function" >include_once()</B ></A >, <A HREF="function.require.html" ><B CLASS="function" >require()</B ></A >, and <A HREF="function.require-once.html" ><B CLASS="function" >require_once()</B ></A > are enabled through <TT CLASS="literal" >parent_include</TT >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="runkit.sandbox.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.runkit-class-adopt.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Runkit_Sandbox</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.runkit.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >runkit_class_adopt</TD ></TR ></TABLE ></DIV ></BODY ></HTML >