# compatibility error

**URL:** <https://discourse.cakephp.org/t/compatibility-error/11222>\
**Category:** Need Help\
**Created:** [May 14, 2023, 7:51pm UTC](https://discourse.cakephp.org/t/compatibility-error/11222 "2023-05-14T19:51:14Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jaelcio](https://avatars.discourse-cdn.com/v4/letter/j/91b2a8/32.png) [@Jaelcio](https://discourse.cakephp.org/u/Jaelcio)\
**Post date:** [May 14, 2023, 7:51pm UTC](https://discourse.cakephp.org/t/compatibility-error/11222/1 "2023-05-14T19:51:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [May 15, 2023, 7:00pm UTC](https://discourse.cakephp.org/t/compatibility-error/11222/2 "2023-05-15T19:00:15Z")

</div>

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](https://github.com/cakephp/app/blob/4.x/composer.json#L15) doesn’t use [bake 1.x](https://github.com/cakephp/bake/blob/1.x/src/Shell/BakeShell.php#L54) (which you seem to use)

---

<div class="post-metadata">

**Author:** ![geaslu](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/geaslu/32/2839_2.png) [@geaslu](https://discourse.cakephp.org/u/geaslu)\
**Post date:** [August 11, 2023, 4:03pm UTC](https://discourse.cakephp.org/t/compatibility-error/11222/3 "2023-08-11T16:03:37Z")

</div>

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 🙂  
…

> “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)

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [August 11, 2023, 7:13pm UTC](https://discourse.cakephp.org/t/compatibility-error/11222/4 "2023-08-11T19:13:47Z")

</div>

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

> **[Home](https://github.com/cakephp/cakephp/wiki)**
>
> CakePHP: The Rapid Development Framework for PHP - Official Repository - cakephp/cakephp

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

---

<div class="post-metadata">

**Author:** ![geaslu](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/geaslu/32/2839_2.png) [@geaslu](https://discourse.cakephp.org/u/geaslu)\
**Post date:** [August 16, 2023, 8:39am UTC](https://discourse.cakephp.org/t/compatibility-error/11222/5 "2023-08-16T08:39:35Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [August 16, 2023, 9:00am UTC](https://discourse.cakephp.org/t/compatibility-error/11222/6 "2023-08-16T09:00:28Z")

</div>

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:

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

```

See [4.2 Migration Guide - 4.x](https://book.cakephp.org/4/en/appendices/4-2-migration-guide.html#deprecations)

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

---

<div class="post-metadata">

**Author:** ![geaslu](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/geaslu/32/2839_2.png) [@geaslu](https://discourse.cakephp.org/u/geaslu)\
**Post date:** [August 16, 2023, 9:17am UTC](https://discourse.cakephp.org/t/compatibility-error/11222/7 "2023-08-16T09:17:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [August 16, 2023, 9:26am UTC](https://discourse.cakephp.org/t/compatibility-error/11222/8 "2023-08-16T09:26:39Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![geaslu](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/geaslu/32/2839_2.png) [@geaslu](https://discourse.cakephp.org/u/geaslu)\
**Post date:** [August 16, 2023, 2:49pm UTC](https://discourse.cakephp.org/t/compatibility-error/11222/9 "2023-08-16T14:49:34Z")

</div>

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/](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

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [August 16, 2023, 3:25pm UTC](https://discourse.cakephp.org/t/compatibility-error/11222/10 "2023-08-16T15:25:19Z")

</div>

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](https://github.com/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](https://book.cakephp.org/4/en/appendices/4-4-migration-guide.html#errorhandler-consoleerrorhandler)

---

<div class="post-metadata">

**Author:** ![geaslu](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/geaslu/32/2839_2.png) [@geaslu](https://discourse.cakephp.org/u/geaslu)\
**Post date:** [August 16, 2023, 4:01pm UTC](https://discourse.cakephp.org/t/compatibility-error/11222/11 "2023-08-16T16:01:43Z")

</div>

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: /

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [August 16, 2023, 4:24pm UTC](https://discourse.cakephp.org/t/compatibility-error/11222/12 "2023-08-16T16:24:26Z")

</div>

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

> <https://github.com/cakephp/app/blob/4.x/src/Application.php#L91>

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:

> <https://github.com/cakephp/app/blob/4.x/templates/Error/error500.php>

---

<div class="post-metadata">

**Author:** ![geaslu](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/geaslu/32/2839_2.png) [@geaslu](https://discourse.cakephp.org/u/geaslu)\
**Post date:** [August 17, 2023, 12:27pm UTC](https://discourse.cakephp.org/t/compatibility-error/11222/13 "2023-08-17T12:27:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [August 17, 2023, 12:59pm UTC](https://discourse.cakephp.org/t/compatibility-error/11222/14 "2023-08-17T12:59:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![geaslu](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/geaslu/32/2839_2.png) [@geaslu](https://discourse.cakephp.org/u/geaslu)\
**Post date:** [August 17, 2023, 1:51pm UTC](https://discourse.cakephp.org/t/compatibility-error/11222/15 "2023-08-17T13:51:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [August 17, 2023, 2:15pm UTC](https://discourse.cakephp.org/t/compatibility-error/11222/16 "2023-08-17T14:15:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![geaslu](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/geaslu/32/2839_2.png) [@geaslu](https://discourse.cakephp.org/u/geaslu)\
**Post date:** [August 18, 2023, 9:23am UTC](https://discourse.cakephp.org/t/compatibility-error/11222/17 "2023-08-18T09:23:36Z")

</div>

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](https://cakephp-datatables.readthedocs.io/en/latest/)” 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
