Skip to content

Commit 9491dc5

Browse files
committed
Fix 'var_export does not handle circular references' pb
1 parent cc92b7d commit 9491dc5

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/Ubiquity/debug/Debugger.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Ubiquity\debug$Debugger
2020
* This class is part of Ubiquity
2121
* @author jc
22-
* @version 1.0.1
22+
* @version 1.0.2
2323
*
2424
*/
2525
class Debugger {
@@ -150,7 +150,15 @@ private static function displayVar($variable){
150150
if(\is_object($variable)){
151151
return \get_class($variable).'@'.\spl_object_hash($variable);
152152
}
153-
return \var_export($variable,true);
153+
if(!self::isRecursive($variable)) {
154+
return \var_export($variable, true);
155+
}
156+
return 'Recursive array!';
157+
}
158+
159+
private static function isRecursive($array){
160+
$dump = \print_r($array, true);
161+
return \strpos($dump, '*RECURSION*') !== false;
154162
}
155163

156164

@@ -221,7 +229,7 @@ private static function showTrace($trace,$index){
221229
$file=$trace['file'];
222230
$attr=UString::cleanAttribute($callClass.".".$callFunction);
223231
self::$variables[$attr]=[];
224-
if($file!=null) {
232+
if($file!=null && \file_exists($file)) {
225233
$class = ClassUtils::getClassFullNameFromFile($file);
226234
if ($class != null && $class != '\\' && (\class_exists($class) || \trait_exists($class))) {
227235
$method = UIntrospection::getMethodAtLine($class, $line);
@@ -322,7 +330,10 @@ private static function getFooter(){
322330
}
323331

324332
private static function getFileContent($file){
325-
return \htmlentities(\file_get_contents($file));
333+
if(\file_exists($file)) {
334+
return \htmlentities(\file_get_contents($file));
335+
}
336+
return "$file not found!";
326337
}
327338

328339
private static function loadView($name,$data){

0 commit comments

Comments
 (0)