Bug #80941 [Opn->Nab]: function __construct() don't pass $var to context GLOBAL

From: Date: Thu, 08 Apr 2021 15:12:50 +0000
Subject: Bug #80941 [Opn->Nab]: function __construct() don't pass $var to context GLOBAL
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233316@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80941&edit=1

 ID:                 80941
 Updated by:         dharman@php.net
 Reported by:        rg at mejoramos dot com
 Summary:            function __construct() don't pass $var to context
                     GLOBAL
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Output Control
 Operating System:   any
 PHP Version:        8.0.3
 Block user comment: N
 Private report:     N

 New Comment:

This looks correct to me. $ManyFunctionsNeedThisVar is empty in global scope. I think
your confusion comes from the fact that you have another variable with the same name in a local
scope within the constructor. Local scope and global scope are not the same.


Previous Comments:
------------------------------------------------------------------------
[2021-04-08 15:00:19] rg at mejoramos dot com

Description:
------------
no't possible pass $VAR to GLOBAL context without used ARRAY $GLOBALS, please see the code.

Test script:
---------------
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

function OtherFunction(){
	GLOBAL $ManyFunctionsNeedThisVar;
	print_r($GLOBALS['a']);
	print_r($ManyFunctionsNeedThisVar);
	}

class OtherClass{
	function __construct(){
		$GLOBALS['a'] = 888;
		$ManyFunctionsNeedThisVar = 777;
		OtherFunction();
		}
	}

$OtherObject = new OtherClass();



Expected result:
----------------
String concatenated, correct output:

888777

Actual result:
--------------
888


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80941&edit=1


Thread (5 messages)

« previous php.bugs (#233316) next »