1

I am using PHP8 and the project is in Cakephp4. For any single notice or warning, it gives Template Exception Error and breaks the project.

Fatal error: Type of Cake\View\Exception\MissingTemplateException::$file must be string (as in class Exception)

Is there any solution for this issue, so that notice or warnings can be excluded and the view will work fine?

Alisa
  • 313
  • 5
  • 20
  • https://book.cakephp.org/4/en/development/errors.html – Daniel W. Mar 21 '22 at 10:20
  • When working on php5 or php7, simple warnings or notices are handled automatically and it do not break the view. Why this happens when working with PHP8? – Alisa Mar 21 '22 at 10:25
  • Please put the errors in the question body, not in the title. The error message says "Fatal error", it doesn't say "Notice" or "Warning". – Daniel W. Mar 21 '22 at 10:53
  • 1
    The file https://github.com/cakephp/cakephp/blob/4.x/src/View/Exception/MissingTemplateException.php has `$file` in the constructor where in PHP8 it has the signature `string $file`. Maybe Cakephp4 is not PHP8 ready – Daniel W. Mar 21 '22 at 11:01
  • Please always mention the exact CakePHP version that you are using (last line in `vendor/cakephp/cakephp/VERSION.txt` or run `bin/cake version`). The problem you're seeing has been [**fixed in 4.3.0**](https://github.com/cakephp/cakephp/pull/15529). – ndm Mar 21 '22 at 12:16

1 Answers1

1

The Fatal error comes from the following file:

https://github.com/cakephp/cakephp/blob/4.x/src/View/Exception/MissingTemplateException.php

But the problem is already solved in the most current 4.3.0 version,

where the property $file got replaced by $filename to not conflict with the property $file in \Exception.

You should update CakePHP and to get rid of the error.

Daniel W.
  • 31,164
  • 13
  • 93
  • 151
  • 1
    Strict typing does not affect inherited method signature compatibility behavior, also constructors are exempt from that anyways, and on top of that it's actually valid to not declare the type in an overridden method ;) The problem was the class' `$file` property, and PHP 8.1 changing some exception properties to be typed. This has been [**fixed some time ago**](https://github.com/cakephp/cakephp/pull/15529), so the user is most likely using an "older" 4.x version. – ndm Mar 21 '22 at 12:16
  • "the user is most likely using an "older" 4.x version" => That's why I didnt find `$file` as a property but `$filename`. Thanks for your explanation! – Daniel W. Mar 21 '22 at 12:56