top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What are php global variables?

0 votes
570 views
What are php global variables?
posted May 31, 2018 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

Global scope refers to any variable that is defined outside of any function. PHP also stores all global variables in an array called $GLOBALS[index]. Its index is the name of the variable. This array is also accessible from within functions and can be used to update global variables directly.

answer Jun 25, 2018 by Manish Tiwari
0 votes

Hey, In php SUPERGLOBAL is class for variable like global and others,

$GLOBALS is a PHP super global variable which is used to access global variables from anywhere in the PHP script (also from within functions or methods). PHP stores all global variables in an array called $GLOBALS[index].
Here is the exammple of it:+

<?php
$s = 25;
$t = 50;
function subtraction()
{
$GLOBALS['v'] = $GLOBALS['t'] - $GLOBALS['s'];
} 
subtraction();
echo $v;
?> 
answer Aug 1, 2019 by Siddhi Patel
Similar Questions
0 votes

I want to use session to pass variables through pages using php.
Site structure is:
1. header.php
2. column.php
3. footer.php
4. index.php
Pages 1, 2 & 3 are included into the index.php.

In header.php page, there is a drop down, in which links(cities) are placed where users will select city.
Now, I want to do code to store selected values into a variable and pass to multiple pages.

Please help on this..

0 votes

I have a question about using a php user class and session variables. Let's say that I have managed to create a user class that finds a particular person from the database query.

As I move about the site from page to page it would be nice to be able to use the current user inside the user class without needing to re – look them up in the database multiple times

Q: so is there a way to combine the current active user in the class with session variables so that they can be used multiple times? If so, how would this work?

0 votes
{"general":{
 "round-corner":"0",
 "border-stroke":"2",
 "background-color":"#ffffff"
 }
}

I have this json string, I know that php variable names doesn't support dashes. So what to do in this case ?

+1 vote

Why I can't read static variables of a child class, even so the variable is protected or public?

Here's what I tried:

class A {
 protected static $foo = "bar";
}

class B {
 public function readFoo() {
 return self::$foo;
 }
}

When now calling B::readFoo, I get the following error:

var_dump((new B())->readFoo());

PHP Fatal error: Access to undeclared static property: B::$foo in php shell code on line 1
PHP Stack trace:
PHP 1. {main}() php shell code:0
PHP 2. B->readFoo() php shell code:1

Fatal error: Access to undeclared static property: B::$foo in php shell
code on line 1

Call Stack:
 86.2643 231224 1. {main}() php shell code:0
 86.2666 231352 2. B->readFoo() php shell code:1
...