All Questions
807
questions
0
votes
0
answers
94
views
Adding new reference to any item in array affects behaviour of the array
I've seen many questions about this (one of them here)
$a = array('a', 'b', 'c', 'd');
foreach ($a as &$v) { }
foreach ($a as $v) { }
print_r($a);
and I get the answers, you shouldn't be ...
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 ...
0
votes
1
answer
46
views
get root path of linux hosting
im trying to get the main path to use it in my code insted of using this way
include "../../../lib/phpspreadsheet/vendor/autoload.php";
and call it like this way
include $root_path . "...
0
votes
1
answer
182
views
how can we add a "package" using composer where it is available on github, I do found one work, but this one doesn't
we can add a github repo as below then run composer install
"config": {
"allow-plugins": {
"composer/installers": true
}
...
0
votes
0
answers
31
views
php script with "&" in reference variable [duplicate]
I have a script php code
<?php
class A
{
public $x;
}
$a = new A();
$a->x = 10;
$b = &$a;
$b = new A();
$b->x = 20;
echo $a->x;
When try to understand code I think the result ...
0
votes
1
answer
37
views
Can I store previous data and access it if new data cannot be obtained?
I am new to coding and trying to complete a task using PHP. I am scraping a web page on my company's web server which displays a count I need. However, if the user logs out of this page, the page ...
0
votes
1
answer
73
views
PHP Error "Creating default object from empty value": How can this happen here?
class Registry {
public $reg = null;
static function _access(&$obj, &$accessor = null) {
if ($obj === null || !is_a($obj, __CLASS__)) {
$obj = new Registry();
}
$...
0
votes
1
answer
52
views
Why does this reference passing not work as expected? [duplicate]
Consider the following code:
class FOO {
public $v = [];
function &refv1() {
return $this->v[1];
}
function refv2(&$ref) {
$ref = &$this->v[2];
}
}
$FOO = new FOO(...
2
votes
0
answers
108
views
Why does a php array in two foreach loops lead to an infinite loop?
I have this PHP code:
$array = [1, 2, 3];
$counter = 0;
foreach($array as &$elem){
test();
$counter++;
if($counter >= 10){
return;
}
}
function test(){
global $...
0
votes
0
answers
56
views
How to return a variable by reference in PHP?
This is my code:
function &query_test(....)
{
$ret = array(....);
return ($ret);
}
Why do I get a strict warning on PHPStorm saying
"Only variables can be returned by reference"
I ...
0
votes
2
answers
107
views
Modify third level of a multidimensional array by reference using nested loops
I want to change all of the 0 values to a random number between 1 and 6 in the following input array.
$_SESSION['diceRoll'] = [
["save_1" => ["pos1" => 0, "pos2"...
1
vote
0
answers
35
views
Are PHP zvals mutable?
I've been reading about memory management in PHP and learned that variables in PHP copy the reference to zvals as long as you don't do a write operation (copy on write paradigm).
https://www....
0
votes
1
answer
99
views
Dynamic reference to files and classes in PHP regardless of the main folder path
I'm working on a custom CMS in PHP and I currently have a file structure like this
includes/autoload.php
index.php
In my index.php file I reference an autoload class which autoloads all my other ...
0
votes
3
answers
2k
views
Create a unique ID based on the value in a row for MySQL [closed]
I am in the process of creating a web application for a genealogy project. I want each person I add onto the database to have a unique id, based on the first 3 characters of their surname (let's call ...
7
votes
4
answers
978
views
Why is the __get() magic method called when trying to assign a reference to a property object?
class Test
{
public $prop1;
public function __get(string $n)
{
echo '__GET: '.$n.' - but why?<br>';
die;
}
}
$t = new Test();
$x1 = new \stdClass();
$t->prop2 ...