note 68614 added to language.oop5.autoload

From: Date: Thu, 03 Aug 2006 13:39:52 +0000
Subject: note 68614 added to language.oop5.autoload
Groups: php.notes 
Request: Send a blank email to php-notes+get-115516@lists.php.net to get a copy of this message
in response to alexey at renatasystems dot org: You may add `global $somedata; before $somedata = 'Some data';` and it should work as expected. file bar.class.php: <?php global $somedata; $somedata = 'Some data'; /* global scope in common way */ class bar { function __construct() { global $somedata; /* reference to global scope variable */ if ( isset($somedata) ) { var_dump($somedata); } else { die('No data!'); } } } ?> 'common way': <?php require 'bar.class.php'; $foo = new bar(); ?> '__autoload way': <?php function __autoload($classname) { require $classname . '.class.php'; } $foo = new bar(); ?> Both 'comon way' and '__autoload way' should give same result: string(9) "Some data" ---- Server IP: 193.219.81.76 Probable Submitter: 85.206.172.198 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.autoload.php Edit -- https://master.php.net/note/edit/68614 Del: integrated -- https://master.php.net/note/delete/68614/integrated Del: useless -- https://master.php.net/note/delete/68614/useless Del: bad code -- https://master.php.net/note/delete/68614/bad+code Del: spam -- https://master.php.net/note/delete/68614/spam Del: non-english -- https://master.php.net/note/delete/68614/non-english Del: in docs -- https://master.php.net/note/delete/68614/in+docs Del: other reasons-- https://master.php.net/note/delete/68614 Reject -- https://master.php.net/note/reject/68614 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115516) next »