Skip to content

Commit 45f3322

Browse files
Lonny Kapelushniksmalyshev
authored andcommitted
var_export outputs an E_WARNING when recursion is detected
1 parent 81c6a06 commit 45f3322

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

ext/standard/tests/general_functions/var_export_error2.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ var_export($obj, true);
1515
===DONE===
1616
--EXPECTF--
1717

18-
Fatal error: Nesting level too deep - recursive dependency? in %s on line 9
18+
Warning: var_export does not handle circular references in %s on line 9
19+
===DONE===

ext/standard/tests/general_functions/var_export_error3.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ var_export($a, true);
1515
===DONE===
1616
--EXPECTF--
1717

18-
Fatal error: Nesting level too deep - recursive dependency? in %s on line 9
18+
Warning: var_export does not handle circular references in %s on line 9
19+
===DONE===

ext/standard/var.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,11 @@ PHPAPI void php_var_export_ex(zval **struc, int level, smart_str *buf TSRMLS_DC)
453453
break;
454454
case IS_ARRAY:
455455
myht = Z_ARRVAL_PP(struc);
456+
if(myht && myht->nApplyCount > 0){
457+
smart_str_appendl(buf, "NULL", 4);
458+
zend_error(E_WARNING, "var_export does not handle circular references");
459+
return;
460+
}
456461
if (level > 1) {
457462
smart_str_appendc(buf, '\n');
458463
buffer_append_spaces(buf, level - 1);
@@ -469,6 +474,11 @@ PHPAPI void php_var_export_ex(zval **struc, int level, smart_str *buf TSRMLS_DC)
469474

470475
case IS_OBJECT:
471476
myht = Z_OBJPROP_PP(struc);
477+
if(myht && myht->nApplyCount > 0){
478+
smart_str_appendl(buf, "NULL", 4);
479+
zend_error(E_WARNING, "var_export does not handle circular references");
480+
return;
481+
}
472482
if (level > 1) {
473483
smart_str_appendc(buf, '\n');
474484
buffer_append_spaces(buf, level - 1);

0 commit comments

Comments
 (0)