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)
- 8.4.0alpha2 fails to build: `error: redefinition of typedef โzend_stringโ` HOT 13
- BUG : Compiling opcache extensions statically into ZTS PHP , JIT bug HOT 6
- In Czech function have bad order with diacritic HOT 11
- IntlChar::foldCase()'s $option is not optional HOT 3
- Support typed variables HOT 3
- The `IntlChar::getBidiPairedBracket()` method is not defined HOT 2
- Add support for all flags from mysql in the PDO MySql driver in the getColumnMeta function.
- php_random_default_engine() is not C++ conforming HOT 4
- PHP interpretor stops on ?> inside comment HOT 10
- _ir_RSTORE: Assertion `ctx->control' failed HOT 3
- Segmentation fault (core dumped) in ext/pgsql/tests/gh13519.phpt HOT 10
- Memory issues yield vs yield from HOT 4
- Compiling php_random_pcgoneseq128xslrr64_rotr64() triggers C4146 HOT 5
- Modifying the $value in a Property Hook setter alters the stack trace HOT 3
- Segfault / Assertion failed: (p->refcount > 0), function zend_gc_delref, file zend_types.h, line 1342 HOT 3
- Memory allocation error: pdo-odbc HOT 11
- var_dump doesn't actually work on XMLReader
- session.lazy_write only implemented if user defines custom handler with updateTimestamp method - Incorrect behavior HOT 2
- Unexpected null pointer in Zend/zend_smart_str.h HOT 2
- Signature of abstract set hook not enforced
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.