<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.arrayaccess.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'arrayaccess.offsetget.php',
    1 => 'ArrayAccess::offsetGet',
    2 => '获取一个偏移位置的值',
  ),
  'up' => 
  array (
    0 => 'class.arrayaccess.php',
    1 => 'ArrayAccess',
  ),
  'prev' => 
  array (
    0 => 'arrayaccess.offsetexists.php',
    1 => 'ArrayAccess::offsetExists',
  ),
  'next' => 
  array (
    0 => 'arrayaccess.offsetset.php',
    1 => 'ArrayAccess::offsetSet',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'language/predefined/arrayaccess/offsetget.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="arrayaccess.offsetget" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ArrayAccess::offsetGet</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">ArrayAccess::offsetGet</span> &mdash; <span class="dc-title">获取一个偏移位置的值</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-arrayaccess.offsetget-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>ArrayAccess::offsetGet</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$offset</code></span>): <span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span></div>

  <p class="para rdfs-comment">
   返回指定偏移位置的值。
  </p>
  <p class="para">
   当检查一个偏移位置是否为 <span class="function"><a href="function.empty.php" class="function">empty()</a></span> 时，会执行此方法。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-arrayaccess.offsetget-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">offset</code></dt>
     <dd>
      <p class="para">
       需要获取的偏移位置。
      </p>
     </dd>
    
   </dl>
  </p>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-arrayaccess.offsetget-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   可返回任何类型。
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-arrayaccess.offsetget-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
    <p class="para">
      此方法的实现可以通过引用返回。
      这使得可以间接修改 <span class="classname"><a href="class.arrayaccess.php" class="classname">ArrayAccess</a></span> 对象，能够重载数组的维度。
    </p>
    <p class="para">
      直接修改是完全替代数组维度的值，例如 <code class="literal">$obj[6] = 7</code>。
     另一方面，间接修改是指仅修改某个维度中的一部分，或者传引用的方式赋值一个维度，
     例如 <code class="literal">$obj[6][7] = 7</code> 和 <code class="literal">$var =&amp; $obj[6]</code>。
      使用 <code class="literal">++</code> 自增或者使用 <code class="literal">--</code> 
      自减也是通过间接修改的方式实现的。
    </p>
    <p class="para">
      直接修改会触发对 <span class="function"><a href="arrayaccess.offsetset.php" class="function">ArrayAccess::offsetSet()</a></span> 
      的调用，而间接修改则会触发对 <span class="function"><strong>ArrayAccess::offsetGet()</strong></span>
      的调用。在这种情况下， <span class="function"><strong>ArrayAccess::offsetGet()</strong></span>
      的实现必须能通过引用返回，否则会引发 <strong><code><a href="errorfunc.constants.php#constant.e-notice">E_NOTICE</a></code></strong> 消息。
    </p>
  </p></blockquote>
 </div>




 <div class="refsect1 seealso" id="refsect1-arrayaccess.offsetget-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="arrayaccess.offsetexists.php" class="methodname" rel="rdfs-seeAlso">ArrayAccess::offsetExists()</a> - 检查一个偏移位置是否存在</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>