Comments (7)
var_export()
doesn't really support references to begin with. E.g:
$a = ['foo'];
$b = [&$a, &$a];
var_export($b);
Results in:
array (
0 =>
array (
0 => 'foo',
),
1 =>
array (
0 => 'foo',
),
)
Honestly, I'm not sure supporting recursive arrays is a worthwhile goal. Recursive arrays are a foot gun, because many things can trigger fatal errors. E.g.:
$a = [&$a];
var_dump($a === [[]]);
Can you clarify what your use-case is?
from php-src.
@carlosmintfan Thank you for clarifying! In that case, I'd honestly prefer closing this as a #wontfix until we know why we're doing it. But I'll keep this open for a few days for others to chime in.
from php-src.
I don't really have a practical use case for it. This was just an idea how it could be implemented theoretically. :)
from php-src.
$a = [&$a]; var_dump($a === [[]]);
Oh wow, why doesn't this just eval to false?
from php-src.
In this case, we probably could. But encountering recursive elements doesn't necessarily mean the elements are not equal. For example:
$a = [&$a];
$b = [[&$b]];
$a === $b;
These arrays should be equal, but understanding they are equal can get quite tricky. While we could probably find a solution for this but it might impact performance of comparison overall, which would not be a good trade-off IMO. I'm not exactly sure why we're not just throwing an Error
, instead of a fatal error. I'll have a look at that.
from php-src.
In this case, we probably could. But encountering recursive elements doesn't necessarily mean the elements are not equal. For example:
$a = [&$a]; $b = [[&$b]]; $a === $b;These arrays should be equal, but understanding they are equal can get quite tricky. While we could probably find a solution for this but it might impact performance of comparison overall, which would not be a good trade-off IMO. I'm not exactly sure why we're not just throwing an
Error
, instead of a fatal error. I'll have a look at that.
LOL, yeah $var = [&$var] is theoretically the same as $var = [[&$var]] cause Infinity + 1 stays Infinity, but I guess var_dumping them, the output will be different. I'll try it later today.
from php-src.
So yeah,
php > $a = [&$a];
php > $b = [[&$b]];
php > var_dump($a);
array(1) {
[0]=>
*RECURSION*
}
php > var_dump($b);
array(1) {
[0]=>
array(1) {
[0]=>
*RECURSION*
}
}
php >
Hmm, yeah, but it's all theory for me, I don't use this anyway, at least until now. 😄
from php-src.
Related Issues (20)
- Reproducible crash in PHP 8.4 with JIT and Excimer HOT 5
- make test always failed that displays "session.sid_length INI setting is deprecated" on macOS HOT 2
- Memory Leak in xmlCreateIntSubset HOT 6
- Configure error grep illegal option q
- Help, I use crypto asymmetric encryption symmetric key, passed to PHP there is an error! HOT 4
- stream_get_contents/fread timeouts HOT 3
- Allow to build apache2 SAPI same time with other SAPIs HOT 2
- Running out of memory in custom session handler's `write` function causes "Cannot call session save handler in a recursive manner" HOT 4
- Reconsider usages of `gethostbyname_r()` HOT 6
- Require `poll()` for UNIX based OSs and improve emulation for Windows HOT 2
- Build with libxml2 versions 2.9.0 to 2.9.3 fails HOT 6
- Install Redis with PECL fatal error: standard/php_random.h: No such file or directory HOT 4
- OPCache File Inclusion and Function Call Errors: Letter Shifting Issue During High Load on PHP 8.3.10 HOT 17
- Run a nightly build with AVX-512 emulation
- Integer overflow in curl_multi_select HOT 3
- Segmentation fault (access null pointer) in ext/dom/xml_common.h HOT 1
- Signed integer overflow in ext/standard/scanf.c HOT 3
- Stubs: internally modifyable properties are not @readonly HOT 6
- --disable-ipv6 during compilation produces error EAI_SYSTEM not found on php-8.3.10-src HOT 2
- Segmentation fault (access null pointer) in ext/dom/html5_serializer.c HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-src.