<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: globals code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 06 Oct 2008 17:37:09 GMT</pubDate>
    <description>DZone Snippets: globals code</description>
    <item>
      <title>Exploring context and globals with Nu</title>
      <link>http://snippets.dzone.com/posts/show/5781</link>
      <description>From Tim in mailing list:&lt;br /&gt;&lt;br /&gt;Global name definitions are put into the symbol table; that is&lt;br /&gt;slightly more efficient than normal assignments (such as those made&lt;br /&gt;with the set, macro, and function operators), which are kept in&lt;br /&gt;NSDictionaries.  It also makes them easier to use in Nu code that is&lt;br /&gt;called from Objective-C without specifying a context, which you can do&lt;br /&gt;by sending the evalWithContext: message to a parsed code object with a&lt;br /&gt;nil argument. Usually that happens in Objective-C, but since you can&lt;br /&gt;send nearly any ObjC message from Nu, here's a little demo in nush&lt;br /&gt;[ed: I expanded it to show more information]:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;$ nush&lt;br /&gt;Nu Shell.&lt;br /&gt;% (parse "(puts 22)")&lt;br /&gt;(progn (puts 22))&lt;br /&gt;% (set prog (parse "(puts 22)"))&lt;br /&gt;(progn (puts 22))&lt;br /&gt;% (prog class)&lt;br /&gt;NuCell&lt;br /&gt;% (set progx (parse "(puts x)"))&lt;br /&gt;(progn (puts x))&lt;br /&gt;% (progx class)&lt;br /&gt;NuCell&lt;br /&gt;% (set x 23)&lt;br /&gt;23&lt;br /&gt;% (x class)&lt;br /&gt;NSCFNumber&lt;br /&gt;% (eval progx)&lt;br /&gt;23&lt;br /&gt;()&lt;br /&gt;% (prog evalWithContext: nil)&lt;br /&gt;22&lt;br /&gt;()&lt;br /&gt;% (progx evalWithContext: nil)&lt;br /&gt;NuUndefinedSymbol: undefined symbol: x&lt;br /&gt;% (progx evalWithContext: (context))&lt;br /&gt;23&lt;br /&gt;()&lt;br /&gt;% (global x 50)&lt;br /&gt;50&lt;br /&gt;% (progx evalWithContext: (context))&lt;br /&gt;23&lt;br /&gt;()&lt;br /&gt;% (progx evalWithContext: nil)&lt;br /&gt;50&lt;br /&gt;()&lt;/code&gt;</description>
      <pubDate>Fri, 18 Jul 2008 00:19:43 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5781</guid>
      <author>nicwilliams (Dr Nic Williams)</author>
    </item>
    <item>
      <title>Emulate register_globals off</title>
      <link>http://snippets.dzone.com/posts/show/2723</link>
      <description>&lt;code&gt;&lt;br /&gt;function unregister_GLOBALS()&lt;br /&gt;{&lt;br /&gt;if (!ini_get('register_globals')) {&lt;br /&gt;       return;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   // Might want to change this perhaps to a nicer error&lt;br /&gt;   if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS'])) {&lt;br /&gt;       die('GLOBALS overwrite attempt detected');&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   // Variables that shouldn't be unset&lt;br /&gt;   $noUnset = array('GLOBALS',  '_GET',&lt;br /&gt;                     '_POST',    '_COOKIE',&lt;br /&gt;                     '_REQUEST', '_SERVER',&lt;br /&gt;                     '_ENV',    '_FILES');&lt;br /&gt;&lt;br /&gt;   $input = array_merge($_GET,    $_POST,&lt;br /&gt;                         $_COOKIE, $_SERVER,&lt;br /&gt;                         $_ENV,    $_FILES,&lt;br /&gt;                         isset($_SESSION) &amp;&amp; is_array($_SESSION) ? $_SESSION : array());&lt;br /&gt;  &lt;br /&gt;   foreach ($input as $k =&gt; $v) {&lt;br /&gt;       if (!in_array($k, $noUnset) &amp;&amp; isset($GLOBALS[$k])) {&lt;br /&gt;           unset($GLOBALS[$k]);&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;unregister_GLOBALS();&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Source: http://www.zend.com/manual/faq.misc.php#faq.misc.registerglobals</description>
      <pubDate>Wed, 27 Sep 2006 15:57:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2723</guid>
      <author>stancell (Algimantas Stancelis)</author>
    </item>
  </channel>
</rss>
