var_export does not handle circular references
anuj9196 opened this issue · 3 comments
Addding this line to my controller
public $components = [
'RequestHandler' => [
'viewClassMap' => ['csv' => 'CsvView.Csv']
]
];
is giving error as
var_export does not handle circular references
Context is
$name = 'RequestHandler'
$config = [
'viewClassMap' => [
'csv' => 'CsvView.Csv'
]
]
$existing = object(Cake\Controller\Component\RequestHandlerComponent) {
'components' => [],
'implementedEvents' => [
'Controller.startup' => 'startup',
'Controller.beforeRender' => 'beforeRender',
'Controller.beforeRedirect' => 'beforeRedirect'
],
'_config' => [
'checkHttpCache' => true,
'viewClassMap' => [
[maximum depth reached]
],
'inputTypeMap' => [
[maximum depth reached]
],
'enableBeforeRedirect' => true
]
}
$msg = 'The "RequestHandler" alias has already been loaded with the following config: '
$hasConfig = true
$existingConfig = [
'checkHttpCache' => true,
'viewClassMap' => [
'json' => 'Json',
'xml' => 'Xml',
'ajax' => 'Ajax'
],
'inputTypeMap' => [
'json' => [
(int) 0 => 'json_decode',
(int) 1 => true
],
'xml' => [
(int) 0 => [
[maximum depth reached]
]
]
],
'enableBeforeRedirect' => true
]
$fail = true
$value = [
'csv' => 'CsvView.Csv'
]
$key = 'viewClassMap'
We don't call var_export
within this plugin. Is there a place in your codebase or maybe a stacktrace for this error?
I'm not sure why it happens, but I got the same message. The following information might help you guys. Ofcourse this is just my situation that (maybe) happens to include Crud and CakePHP together ( this might also happen without Crud, who knows at the moment ).
My situation: Build API's before, but wanted to build something real quick without my normal code/overhead (so: just a demo). I was following the steps from: How to build a CakePHP3 API in minutes. My code is mostly equal to that ( I know this does not include my small changes, which might give the error and also some updates to CakePHP3 and other packages after the tutorial was written ( because some things needed to be fixed to run @cakephp 3.6).
Also: I have App ( normal classes and folders for Controller etc. ), but also have an Api prefix, with /src/Controller/Api/AppController.php being the main class ( not extending from src/Controller/AppController but from Cake's Controller class ). The prefix works and I do get results for /api/quotes/index.json (among others).
Anyway; some stuff:
- I got this message (it seems, from a different source than the OP):
Warning (2): var_export does not handle circular references [CORE/src/Core/ObjectRegistry.php, line 147]
Which shows where it comes from (in my case), namely: "ObjectRegistry" from CakePHP itself (not CRUD). Thus, this probably explains why @josegonzalez said "we don't callvar_export
in this plugin". It must come from some combination of things that eventually hits the wrong note in ObjectRegistry - Stacktrace:
var_export - [internal], line ??
Cake\Core\ObjectRegistry::_checkDuplicate() - CORE/src/Core/ObjectRegistry.php, line 147
Cake\Core\ObjectRegistry::load() - CORE/src/Core/ObjectRegistry.php, line 86
Cake\Controller\Controller::loadComponent() - CORE/src/Controller/Controller.php, line 334
Cake\Controller\Controller::_loadComponents() - CORE/src/Controller/Controller.php, line 642
Cake\Controller\Controller::__construct() - CORE/src/Controller/Controller.php, line 275
Cake\Error\ExceptionRenderer::_getController() - CORE/src/Error/ExceptionRenderer.php, line 126
Cake\Error\ExceptionRenderer::__construct() - CORE/src/Error/ExceptionRenderer.php, line 91
Cake\Error\Middleware\ErrorHandlerMiddleware::getRenderer() - CORE/src/Error/Middleware/ErrorHandlerMiddleware.php, line 174
Cake\Error\Middleware\ErrorHandlerMiddleware::handleException() - CORE/src/Error/Middleware/ErrorHandlerMiddleware.php, line 116
Cake\Error\Middleware\ErrorHandlerMiddleware::__invoke() - CORE/src/Error/Middleware/ErrorHandlerMiddleware.php, line 100
Cake\Http\Runner::__invoke() - CORE/src/Http/Runner.php, line 65
Cake\Http\Runner::run() - CORE/src/Http/Runner.php, line 51
Cake\Http\Server::run() - CORE/src/Http/Server.php, line 98
[main] - ROOT/webroot/index.php, line 40
It shows it hits loadComponents()
so it might reflect an error in the component config/load. This is the context (from the stacktrace/error):
$name = 'RequestHandler'
$config = [
'enableBeforeRedirect' => true
]
$existing = object(Cake\Controller\Component\RequestHandlerComponent) {
'components' => [],
'implementedEvents' => [
'Controller.startup' => 'startup',
'Controller.beforeRender' => 'beforeRender',
'Controller.beforeRedirect' => 'beforeRedirect'
],
'_config' => [
'checkHttpCache' => true,
'viewClassMap' => [
[maximum depth reached]
],
'inputTypeMap' => [
[maximum depth reached]
],
'enableBeforeRedirect' => false
]
}
$msg = 'The "RequestHandler" alias has already been loaded with the following config: '
$hasConfig = true
$existingConfig = [
'checkHttpCache' => true,
'viewClassMap' => [
'json' => 'Json',
'xml' => 'Xml',
'ajax' => 'Ajax'
],
'inputTypeMap' => [
'json' => [
(int) 0 => 'json_decode',
(int) 1 => true
],
'xml' => [
(int) 0 => [
[maximum depth reached]
]
]
],
'enableBeforeRedirect' => false
]
$fail = true
$value = true
$key = 'enableBeforeRedirect'
Which shows "RequestHandler already loaded" in $msg (as it did in the OP's post).
Debugging and checking a little more, I've found that there seems to be a difference in loading via $components = ['RequestHandler' => ['enableBeforeRedirect' => true]]
and loading via loadComponent() in the main /src/Controller/AppController::initialize() .
So; writing this comment solved my problem it seems. All var_export messages disappear when I remove the $components version in AppController and replace it with the initialize() version ( in the same class, no other changes ). That works.
Might help OP in his situation ( even though this is a year old issue ).
Conclusion: Don't think it's a CRUD/csvview issue, probably just wrong configuration in the main app/routing.
Thanks for the update!