|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80941 function __construct() don't pass $var to context GLOBAL
Submitted: 2021-04-08 15:00 UTC Modified: 2021-04-08 15:12 UTC
From: rg at mejoramos dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: 8.0.3 OS: any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: rg at mejoramos dot com
New email:
PHP Version: OS:


 [2021-04-08 15:00 UTC] rg at mejoramos dot com
no't possible pass $VAR to GLOBAL context without used ARRAY $GLOBALS, please see the code.

Test script:
ini_set('display_errors', 1);

function OtherFunction(){
	GLOBAL $ManyFunctionsNeedThisVar;

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

$OtherObject = new OtherClass();

Expected result:
String concatenated, correct output:


Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-08 15:12 UTC]
-Status: Open +Status: Not a bug
 [2021-04-08 15:12 UTC]
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.
 [2021-04-08 15:48 UTC] rg at mejoramos dot com
Thanks master @dharman

when we declare 

$ManyFunctionsNeedThisVar = 777;

this is GLOBAL.

When we declare

	function __construct(){ // --> this is GLOBAL ?
		$GLOBALS['a'] = 888; // --> this is GLOBAL ?
		$ManyFunctionsNeedThisVar = 777; // --> this is GLOBAL ?
 [2021-04-08 16:02 UTC] rtrtrtrtrt at dfdfdfdf dot dfd
why should $ManyFunctionsNeedThisVar in __constrcut(9 be global without "global $ManyFunctionsNeedThisVar" ir $GLOBALS['ManyFunctionsNeedThisVar'];

this are two different vars in different scopes and you really should learn basics:
 [2021-04-08 16:12 UTC] rg at mejoramos dot com
Sorry by my ERROR.

Many thanks by your lesson of Aphril masters

@dharman and @rtrtrtrtrt

I am wrong about this,
I am sorry and thanks by your time.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed May 31 23:03:40 2023 UTC