All Questions
567
questions
1
vote
1
answer
36
views
global variables get different values (web / terminal)
While learning php I came across the following problem.
I don’t understand why I get different values on my local site and in the terminal when I run the following code:
function scopeTest(): int
{...
0
votes
1
answer
49
views
Why do different delivery methods have different results when applying PHP's global keyword?
PHP implements the static and global modifier for variables in terms of references. For example, a true global variable imported inside a function scope with the global statement actually creates a ...
1
vote
0
answers
34
views
Changing PHP code which uses PHPs $_REQUEST super global
New to php and have read up on $_REQUEST being strongly discouraged, due to the fact that it makes it nearly impossible to determine the source of the data, and also being a security risk as well.
Not ...
0
votes
0
answers
41
views
Laravel Inertia-React share function with parameters
In Inertia I know I can share datas via HandleInertiaRequests middleware, can I share a function that gets arguments?
Below code (dummy code) gives the error: TypeError: can is not a function
'can' =&...
0
votes
0
answers
21
views
php variable why it is visible in other files without being declared global? [duplicate]
I defined the following files
0.php
<?php
$v='good';
echo 'In file: '.__FILE__." v={$v}<br>\n";
?>
1.php
<?php
require '0.php';
echo 'In file: '.__FILE__." v={$v}<br&...
1
vote
1
answer
140
views
Need more understanding of PHP Float CONSTANTS
So, I just came across these PHP float Constants: PHP_FLOAT_DIG and PHP_FLOAT_EPSILON, and I don't understand both constants (even after studying the official documentation https://www.php.net/manual/...
0
votes
2
answers
66
views
PHP - Way to call a function that creates variables outside in calling context?
I'd like to pull all the names of fields from a submitted form, and create variables from them automatically. Not much of a problem as my code1 below shows. BUT I'd now like to put the code in a ...
-3
votes
1
answer
182
views
why am i getting a fatal error when i run this code?
<?php
if (ini_get('auto_globals_jit'))
// Override setting
$GLOBALS+=['_ENV'=>$_ENV,'_REQUEST'=>$_REQUEST];
// Sync PHP globals with corresponding hive keys
$this->init=$this-&...
2
votes
0
answers
78
views
Do PHP class constants introduce the same global scope problems as normal PHP constants?
I understand the scope problems in PHP that arise from use of constants (as well as the global keyword with normal variables) in functions and classes. I understand Singletons and that I don't have (...
0
votes
2
answers
279
views
Laravel Server Side Event update global variable
I have an SSE event that selects last updates from table 'Newz' ad uses them to select from concerned tables the full data to stream it within the event.
The problem is I start with a global '$lastrec'...
0
votes
1
answer
259
views
Global functions in Symphony application
I thought this would be easy. For troubleshooting, I wish to call my _logger() function from anywhere in my application.
function _logger(?string $msg=null, int $offset=0, bool $time=false):void
{
...
-1
votes
1
answer
46
views
How to pass the language information between actions? [duplicate]
Similar questions exists - I've tried already some solutions from StackOverflow and Google but still no luck - I can't catch a right syntax or right understanding - so let me repeat my question with ...
0
votes
0
answers
31
views
How to access variable from a function in a required file that required another file? Can I do it directly, without using $GLOBALS? [duplicate]
So I have the following 3 files:
index.php
<?php
require("require/functions.php");
$g = getGroup();
var_dump($data);
die();
?>
functions.php
<?php
function ...
0
votes
0
answers
49
views
PHP function doesn't see a global variable if it's not declared global outside of the function
The code from the official example:
<?php
$a = 1;
$b = 2;
function Sum()
{
global $a, $b;
$b = $a + $b;
}
Sum();
echo $b;
?>
Result: 2
If $a and $b are declared global outside the ...
-1
votes
2
answers
116
views
PHP : is there a way to forbid use of global/system function in certain class?
I am using Laravel and there is a helper function app() (the app() function itself is built in in the framework as a global function and I have no intention to modify it) which in my application I ...