compatibility error

Hello,

I have CakePHP installed on a machine with Php 8.2, I just started using Cake and I was having to use Bake, however, whenever I try to run the command it returns this error:

PHP Fatal error: Declaration of Bake\Shell\BakeShell::startup() must be compatible with Cake\Console\Shell::startup(): void in C:\xampp\htdocs\romiseta\vendor\cakephp\bake\src\Shell\BakeShell.php on line 50

Fatal error: Declaration of Bake\Shell\BakeShell::startup() must be compatible with Cake\Console\Shell::startup(): void in C:\xampp\htdocs\romiseta\vendor\cakephp\bake\src\Shell\BakeShell.php on line 50

You seem to be running on an old version of cakephp/bake for some reason.
How did you create your cakephp app? Because the latest version of the cakephp app template doesn’t use bake 1.x (which you seem to use)

Hi, also I have the same error, whene run “bin/cake server” give me this
“Fatal error: Declaration of App\Shell\ConsoleShell::getOptionParser() must be compatible with Cake\Console\Shell::getOptionParser(): Cake\Console\ConsoleOptionParser”

part of my composer file :slight_smile:

“license”: “MIT”,
“require”: {
“php”: “>=5.6”,
“cakephp/cakephp”: “4.1.x”,
“mobiledetect/mobiledetectlib”: “2.*”,

    "cakephp/plugin-installer": "*",
    "dompdf/dompdf": "*",
    "cakephp/migrations": "*"
    
},
"require-dev": {
    "psy/psysh": "@stable",
    "cakephp/debug_kit":"*",
    "cakephp/bake": "*"
},

I use PHP 8.0.29, cake 4.1

Thx for help.

My project begin from 3.6 then I migrate 3.7/8/9/10 → 4.0/1 (I am crazy I know)

PHP 8.0 Support was added in CakePHP 4.2 as you can see here:

So either upgrade to that or use PHP 7.4 till your app is upgraded more.

Thx for the replay, but when I try to execute : “bin/cake upgrade rector --rules cakephp42 ” give me this error

PHP Fatal error: Declaration of App\Shell\ConsoleShell::getOptionParser() must be compatible with Cake\Console\Shell::getOptionParser(): Cake\Console\ConsoleOptionParser in myApp\src\Shell\ConsoleShell.php on line 67

Fatal error: Declaration of App\Shell\ConsoleShell::getOptionParser() must be compatible with Cake\Console\Shell::getOptionParser(): Cake\Console\ConsoleOptionParser in myApp\src\Shell\ConsoleShell.php on line 67

How can I solve this? i’am falling in crazy time…

you don’t have to use the rector upgrade tool since it can only partially fix problems for you.

Besides the fact that the rector tool needs to be executed like that:

bin/cake upgrade rector --rules cakephp42 <path/to/app/src>

See 4.2 Migration Guide - 4.x

so you are missing the last argument there which is the absolute path to your apps src directory.

But you can also just fix the problems in your app as they come along instead of relying on the ugprade tool

Thx for the replay,
I have solve the problem

PHP Fatal error: Declaration of App\Shell\ConsoleShell::getOptionParser() must be compatible with Cake\Console\Shell::getOptionParser(): Cake\Console\ConsoleOptionParser in myApp\src\Shell\ConsoleShell.php on line 67

and after that give me another error in file ruotes.php at thi line : “Plugin::routes();” cause is deprecated… i have comment this line and I have launch this command

bin/cake upgrade rector --rules cakephp42 c:.…\src

And it’s ok.

now when try to launch

bin/cake server

give me to many error:

[Notice (1024)](javascript:void(0);): Undefined property: ErrorController::$viewVars in C:…\src\Controller\AppController.php on line 119 [CORE\src\Controller\Controller.php, line 321]

[Warning (512)](javascript:void(0);): Unable to emit headers. Headers sent in file=C:…\vendor\cakephp\cakephp\src\Error\Debugger.php line=971 [CORE\src\Http\ResponseEmitter.php, line 71]

[Warning (2)](javascript:void(0);): Cannot modify header information - headers already sent by (output started at C:…\vendor\cakephp\cakephp\src\Error\Debugger.php:971) [CORE\src\Http\ResponseEmitter.php, line 168]

[Warning (2)](javascript:void(0);): Cannot modify header information - headers already sent by (output started at C:…i\vendor\cakephp\cakephp\src\Error\Debugger.php:971) [CORE\src\Http\ResponseEmitter.php, line 197]

[Warning (2)](javascript:void(0);): Cannot modify header information - headers already sent by (output started at C:…\vendor\cakephp\cakephp\src\Error\Debugger.php:971) [CORE\src\Http\ResponseEmitter.php, line 197]

An Internal Server Error Occurred

I think something it’s not update… or it’s normal to have too many problems?

Well look at the error. This is something inside your app which is causing the problem

Undefined property: ErrorController::$viewVars in 
C:…\src\Controller\AppController.php on line 119 

So you seem to reference the property $viewVars from the ErrorController inside your AppController

But the ErrorController never had such a $viewVars property in the first place (at least not to my knowledge)

So check that code of yours.

I have solved this problem with this correction in my AppController.php:

    //if (!array_key_exists('_serialize', $this->viewVars) &&
    if (!$this->viewBuilder()->getVar('_serialize') &&
        in_array($this->response->getType(), ['application/json', 'application/xml'])
    ) {
        $this->set('_serialize', true);
    }

but now there’s a now fight…
when launch bin/cake server everything seems ok:

Welcome to CakePHP v4.4.16 Console

App : src
Path: …i\src
DocumentRoot: C:\00_Sviluppo\gestionale-ordini\webroot
Ini Path:

built-in server is running in http://localhost:8765/
You can exit with CTRL-C

so no error, no warning… but… give me only this row:

An Internal Server Error Occurred

can you help me, where is log about local server?

Thx toooooooooo much

I’d say look at either the logs/error.log file or the webserver error.log which I can’t tell you where it is positioned because this depends on your webserver config.

But if you now updated to CakePHP 4.4 I’d recommend you check the files present in cakephp/app (and most certainly there are changes needed in your config directory) to see if everything matches up.

I first thought you are just going to update to CakePHP 4.2 but you are on 4.4 so at least you have to migrate your error handler as explained here:
https://book.cakephp.org/4/en/appendices/4-4-migration-guide.html#errorhandler-consoleerrorhandler

Thx for your patience,
I solved the problem about errorhandler, and i found the log of webserver

that’s it:

Request URL: /
2023-08-16 16:38:22 error: [ArgumentCountError] Too few arguments to function Cake\Routing\Middleware\RoutingMiddleware::__construct(), 0 passed in …\vendor\cakephp\cakephp\src\Http\MiddlewareQueue.php on line 80 and at least 1 expected in …\vendor\cakephp\cakephp\src\Routing\Middleware\RoutingMiddleware.php on line 71
Request URL: /
2023-08-16 16:38:23 error: [Cake\View\Exception\MissingTemplateException] Template file Error\error500.php could not be found.

The following paths were searched:

  • ....templates\Error\error500.php
  • ....\vendor\cakephp\cakephp\templates\Error\error500.php
    in …\vendor\cakephp\cakephp\src\View\View.php on line 1398
    Exception Attributes: array (
    ‘file’ => ‘Error\error500.php’,
    ‘paths’ =>
    array (
    0 => ‘C:\00_Sviluppo\gestionale-ordinitemplates\’,
    1 => ‘C:\00_Sviluppo\gestionale-ordini\vendor\cakephp\cakephp\templates\’,
    ),
    )
    Request URL: /

Well as its stated in your error you seem to build your RoutingMiddleware without any arguments.

But as you can see here you have to pass $this to it

This is what I mean by check all the files in the cakephp/app repository and see if there is anything that has changed compared to your app.

The second error relates to the fact, that you don’t have a error500.php in your template.

It should be positioned in templates/Error/error500.php as you can see here:

Kevin, thx too much, I am arriving at the end of this adventure.
Now i can work on my project in cake4.4 e php 8.2…

You are very expert, can you help me to find a usefull datatable? which is the best for you?

Thx

What do you mean by “find a usefull datatable”?

I mean: a super powerful datatable that handles ajax calls :sunglasses:

I am not aware of any kind of plugin which does that for you.

I found this plugin “wsssoftware/cakephp-datatables” which promises to do everything I need. I have read all the documentation in the site “Welcome — CakePHP DataTables” but unfortunately I can’t figure out how I can use it.
I have to load a table in the frontend with the paginated data of my Model… but I can’t find examples anywhere and in the documentation it doesn’t explain (or I don’t understand). Does anyone have examples of usage?

Thank you