Code Monkey home page Code Monkey logo

cakephp2-php8's Introduction

Fork of CakePHP 2 with support for PHP8

For original README content please check original repository: https://github.com/cakephp/cakephp/tree/2.x

Unfortunately branch 2.x in original repository was taken down.

Why I created this fork? ๐Ÿค”

CakePHP 2 stopped getting updates in the end of 2019 (AFAIR). Unfortunately in my case it's too expensive to migrate to newer versions of CakePHP. I started migrating to Symfony framework, but I still use ORM from CakePHP (and actually I like it). So in order to keep up with the newest PHP versions I decided to create fork of the framework.

Why you should NOT use? โ›”

  • Intention of this fork is to support PHP 8.*. Fork is not going to receive new features. Instead, fork is going to get minimal set of patches to comply with newer versions of PHP.
  • If for example you're still on 5.6 or 7.0, you should not use this fork. Original cakephp/cakephp works perfectly fine on all PHP 7.* versions. You should migrate to newer versions of PHP and keep using original code. Once your application is battle tested on production I suggest migrating to PHP 8.

When you could use this fork? โœ…

Only prerequisite is to have your application already on PHP 7.4. Upgrade project to PHP 8.0 and replace CakePHP with this fork.

Migration

Here are steps I took to migrate my project through all versions to PHP 8.1, maybe it can inspire you:

  1. Decouple your tests from CakeTestCase and other utilities that are coupled to old PHPUnit version.
  2. Once decoupled you can upgrade PHPUnit to the newest version accordingly to your PHP version.
  3. Start upgrading gradually to newer versions of PHP. CakePHP 2 works perfectly fine on 7.0 - 7.4.
  4. Once you're on 7.4 you can switch to 8 and this fork.

Before using this fork โš ๏ธ

  • Tests of CakePHP framework aren't refactored yet to support PHP 8. Main issue is old version of PHPUnit that is tightly coupled to framework's tests. Issue for fixing this situation is here: #7 Framework tests are migrated to PHPUnit 9.*. Github actions are running tests on PHP 8.0, 8.1.
  • Due to lack of tests โ˜๏ธ - you also need to rely on tests in your application after integrating with this fork.
  • If after integration you spot any issues related to framework please let me know by creating an issue or pull request with fix.

Breaking changes

  • In order to get rid of strftime() deprecation notices, it's required to switch to IntlDateFormatter class. This class is available in intl extension. Fork doesn't require it explicitly but to be able to use its functions Symfony ICU Polyfill is installed. To provide strftime behavior compatibility, PHP81_BC\strftime is used. PHP81_BC doesn't fully cover strftime, your code should work but there is a chance you'll get slightly different results. Discussed (here)[#64] and (here)[#65].

Installation

This repository is not available in packagist, therefore your project's composer.json must be changed to point to custom repository.

Example configuration:

{
	"require": {
		"cakephp/cakephp": "dev-master as 2.10.24",
	},
	"repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/kamilwylegala/cakephp2-php8"
        }
    ]
}

It means that composer will look at master branch of repository configured under repositories to resolve update of cakephp/cakephp package.

Changelog

2024-07-24

  • Csrf vulnerabity fix back ported from Cake PHP 3
  • Explicit type hint definition of nullable parameters.

2024-06-05

  • Removed usage of strftime, replaced with Intl extension.

2024-05-24

  • Fix deprecation error in Model: Automatic conversion of false to array is deprecated

2024-05-22

  • Fix deprecation error in I18n: Automatic conversion of false to array is deprecated

2024-02-02

  • str_len deprecation warning fix in CakeResponse (passing null instead of string)

2024-01-19

  • strotime() and preg_split() in CakeResponse deprecation warning fixes (passing null)

2024-01-11

  • preg_replace deprecation warning fixes (passing null instead of string)

2023-12-22

  • preg_quote() passing null fix

2023-12-19

  • Muted dynamic property creation warnings in Controller.php
  • Fix passing a null input to h function (PR #56)
  • Fix Hash class callback callable pattern deprecated (PR #58)

2023-11-13

  • Silence dynamic property creation warning in Model.php

2023-11-02

  • Fixed: unitialized property in Debugger.php

2023-10-20

  • Fallback to empty string from env() in basics.php and request handler.

2023-10-19

  • Removed usage of deprecated redis->getKeys() in favor of redis->keys().
  • Added docker-compose setup to run tests locally.

2023-09-18

  • Fix for ShellDispatcher where null was passed to strpos function.

2023-08-18

  • Fixed PHP8 deprecation notices. Related mostly to passing null as a $haystack value.

2023-06-02

  • Fixed PHP 8.2 deprecation notices in CakeEvent: Creation of dynamic property ... is deprecated.

2023-02-19

  • Fixed PHP 8.1 MySQL test suite.

2023-02-11

  • Fixed PostgreSQL test suite.

2023-01-30

  • PaginatorHelper fix.

2023-01-22

  • Fixed views cache when relative time is specified.

2023-01-11

  • Fixed test suite to run under PHPUnit 9.5 and PHP8. Big kudos to @tenkoma ๐Ÿ‘

2022-10-20

  • MailTransport fix.

2022-10-08

  • Support for full_path when uploading a file, PHP 8.1 only.

2022-09-27

  • Fixed multiple CREATE UNIQUE INDEX statements from schema shell that did not work on PostgreSQL.

2022-03-08

  • Fixed passing params["pass"] argument to invokeArgs when resolving controller action - array_values used to avoid problems with named parameters.

2022-03-03

  • Removed String class.

2022-03-02

  • Fixed ConsoleErrorHandler::handleError to respect error suppression.

2022-01-31

  • Fixed Folder->read, array_values is used to remove keys to prevent usign named arguments in call_user_func_array

2022-01-16

  • Fix Shell ReflectionMethod::__construct default null argument in hasMethod

2022-01-15

  • Readme file update - more explicit content.

2022-01-04

  • Fixed more deprecation notices
    • strtoupper + converting false to array in Mysql.php
    • preg_match where $subject = null in CakeRoute.php
    • strtoupper in DboSource.php
    • Check history for details โ˜๏ธ

2021-12-20

  • Fixed deprecation notices in PHP 8.1 for production code implementations:
    • ArrayAccess
    • Countable
    • IteratorAggregate
  • PHP 8.0 requirement in composer.json
  • Warning: Tests are not updated, Cake's tests rely on old version of PHPUnit so running them may show a lot of deprecations notices. Added issue to cover it: #7

2021-02-24

  • Fixed ErrorHandler accordingly to PHP8 migration guide. Otherwise, error handler is logging too much and doesn't respect configured error_reporting.

cakephp2-php8's People

Contributors

ad7six avatar admad avatar bancer avatar bar avatar ceeram avatar chinpei215 avatar dereuromark avatar dogmatic69 avatar felixge avatar jeremyharris avatar jippi avatar jperras avatar jrbasso avatar kamilwylegala avatar lorenzo avatar majna avatar mariuswilms avatar markstory avatar nateabele avatar phally avatar phpnut avatar predominant avatar ravage84 avatar rchavik avatar renan avatar sebastienbarre avatar shama avatar tenkoma avatar tersmitten avatar tigrang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cakephp2-php8's Issues

Support for PHP 8.2

I am planning to use this fork into a old production environment to make it compatible with some serverless initiatives.

Can you let me know if this library already works in PHP 8.2 otherwise are there any plans to do so?

How to add new package?

I have 2 composer in root project and directory of app. How to add new package and using in controller?

Using Sqlserver "WITH" clause in CakePhp2

I use the Sqlserver "WITH common_table_expression" expression in CakePhp 2.

In Sqlserver.php in the Method "_execute" the Code tests for "SELECT" or "EXEC" to determine if an SQL Statement is valid for Execution.

$sql = trim($sql);
if (strncasecmp($sql, 'SELECT', 6) === 0 || preg_match('/^EXEC(?:UTE)?\s/mi', $sql) > 0) {
$prepareOptions += array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL);
return parent::_execute($sql, $params, $prepareOptions);
}

May it be possible to change the Code in Line 799 to
if ((strncasecmp($sql, 'SELECT', 6) === 0) || (strncasecmp($sql, 'WITH', 4) === 0) || preg_match('/^EXEC(?:UTE)?\s/mi', $sql) > 0) {

so the WITH clause can be used out of the box.

Sorry if the is not the correct way to make suggestions, but i am relatively new to GitHub. ;-)

Problem with debugkit

If I enable debug =1 and debugkit I get a lot of rubbish on my screen (as if jquery could not be called).
Is this happening only to me? Anybody found a solution?

Thanks
Massimo

Require intl extension as a dependency on this repo

As I mentioned on PR #64, CakePHP 2 docs don't require intl PHP extension.
I oppened this issue to discuss the possibility to add intl as an requirement on this repo. With intl we can stop hidding strftime warning deprecations.

How to use this fork?

Sorry, this is not an issue regarding your fork. but, i haven't find any other way to contact you.
i am new on Github.
i built a cakephp project long time ago. now it is not working on php8. so i found this link for solution but i don't know how to use it?
is it ilke, i have to download this directory and after that will have to copy paste all my files (controller, model, view, webroot etc) into this?
please can you explain?
Thank you.

DEPRECATED WARNINGS ON: CORE\Cake\I18n\I18n.php

Deprecated (8192): Automatic conversion of false to array is deprecated [CORE\Cake\I18n\I18n.php, line 448]

Deprecated (8192): Automatic conversion of false to array is deprecated [CORE\Cake\I18n\I18n.php, line 440]

Code:

if ($translations !== false) { =>>>> $this->_domains[$domain][$this->_lang][$this->category] = $translations; $this->_noLocale = false; break 2; }

Unsupported operand types: float + string

When calling an element:

$this->element($file, $data);

I receive "Unsupported operand types: float + string"

STACK TRACE
[CORE/Cake/View/View.php line 971] โ†’ [include()]
[CORE/Cake/View/View.php line 933] โ†’ [View->_evaluate()]
[CORE/Cake/View/View.php line 1224] โ†’ [View->_render()]
[CORE/Cake/View/View.php line 418] โ†’ [View->_renderElement()]
[APP/Plugin/Samples/View/Elements/potency.ctp line 448] โ†’ [View->element()]
[CORE/Cake/View/View.php line 971] โ†’ [include(string)]
[CORE/Cake/View/View.php line 933] โ†’ [View->_evaluate()]
[CORE/Cake/View/View.php line 1224] โ†’ [View->_render()]
[CORE/Cake/View/View.php line 418] โ†’ [View->_renderElement()]
[APP/Plugin/Samples/View/Potencies/view.ctp line 1] โ†’ [View->element()]
[CORE/Cake/View/View.php line 971] โ†’ [include(string)]
[CORE/Cake/View/View.php line 933] โ†’ [View->_evaluate()]
[CORE/Cake/View/View.php line 473] โ†’ [View->_render()]
[CORE/Cake/Controller/Controller.php line 973] โ†’ [View->render()]
[CORE/Cake/Routing/Dispatcher.php line 200] โ†’ [Controller->render()]
[CORE/Cake/Routing/Dispatcher.php line 167] โ†’ [Dispatcher->_invoke()]
[APP/webroot/index.php line 109] โ†’ [Dispatcher->dispatch()]

Thoughts? Due to the way the client requests I have to render the view which calls an element, which in turn calls a separate element. I've done a var dump, there is no mismatch. I'm very confused.

Deprecated (8192): Automatic conversion of false to array is deprecated [CORE\Cake\Model\Model.php, line 1232]

On updating row in a model:

Deprecated (8192): Automatic conversion of false to array is deprecated [CORE\Cake\Model\Model.php, line 1232]

imagen

Trace:

Model::set() - CORE\Cake\Model\Model.php, line 1232
Model::_doSave() - CORE\Cake\Model\Model.php, line 1809
Model::save() - CORE\Cake\Model\Model.php, line 1761
ConfigsController::procesaColaEmail() - APP\Controller\ConfigsController.php, line 2033
ReflectionMethod::invokeArgs() - [internal], line ??
Controller::invokeAction() - CORE\Cake\Controller\Controller.php, line 500
Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 193
Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 167
[main] - APP\webroot\index.php, line 137

cake i18n extract fails on PHP 8.1

Hello,

Many thanks for your port of cakephp2 to php8. It has given me a few extra years to complete the migration of my site to the latest Cake.

When running: $ ./Console/cake i18n extract

... I end up with a fatal error:
PHP Fatal error: Cannot use 'object' as class name as it is reserved in C:\xampp\htdocs\cakephp2-php8\lib\Cake\Core\Object.php on line 18

Attempting to use an old PHP does to bypass this issue does not work and fails with the following:
Fatal error: Declaration of CakeRequest::offsetExists(mixed $name): bool must be compatible with ArrayAccess::offsetExists($offset) in C:\xampp\htdocs\cakephp2-php8\lib\Cake\Network\CakeRequest.php on line 35

Tests with PHPUnit ^9.5 and PHP 8

If someone can help me, I have problems with PHPUnit testing. Please correct me if I am doing something wrong, but
when i try to run Cake tests I found several problems. Let's use command from CakePHP Doc:

Console/cake test app AllTests

Issue 1.
First I receive an error from main test dispatcher file /cakephp2-php8/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php method loadTestFramework. Problem is that method try to check does class exist with old PHPUnit namespace in class name with underscores PHPUnit_Framework_TestCase. That is for older versions of PHPUnit (such as 4.*)

line 152 - if (class_exists('PHPUnit_Framework_TestCase')) {...

It is working when i replace old classname with this PHPUnit\Framework\TestCase.
That is the problem in multiple files, and on some places PHPUnit classnames are written ok with new namespace. So problem is in that mix where some files use new namespace with class name and some files use old style
I needed to replace all old namespaces with new one (approximate 65 times inside 13 files)
Here is the list of files:
screen 1

Issue 2.
After all replaces, I found that some CakeTest classes extends final PHPUnit classes which cause an error. Than I edited my vendor/phpunit I removed final prefix in these classes:

Class CakeTestLoader cannot extend final class PHPUnit\Runner\StandardTestSuiteLoader in lib/Cake/TestSuite/CakeTestLoader.php
Class CakeTestRunner cannot extend final class PHPUnit\TextUI\TestRunner in lib/Cake/TestSuite/CakeTestCase.php

Issue 3.
Than I get error for method declaration which is not compatible with extended PHPUnit class methods inside Cake/TestSuite/CakeTestCase.php:

Declaration of CakeTestCase::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp()
Declaration of CakeTestCase::tearDown() must be compatible with PHPUnit\Framework\TestCase::tearDown()

Here I also fix PHPUnit\Framework\TestCase instde vendor/phpunit.


After I fix all 3 issues my command for testing is working now Console/cake test app AllTests.

I think that this is not the right way to do because i made changes inside core framework files, and also changes inside vendor/phpunit directory.

Is there another way to run cake tests inside this framework?

Thanks in advanced

Doesn't support PHP 7.4 version? Error message displayed

PHP Fatal error:  Declaration of CakeRequest::offsetExists(mixed $name): bool must be compatible with ArrayAccess::offsetExists($offset) in /Users/blahblah/development/cakephp2-php8/lib/Cake/Network/CakeRequest.php on line 1149

Fatal error: Declaration of CakeRequest::offsetExists(mixed $name): bool must be compatible with ArrayAccess::offsetExists($offset) in /Users/blahblah/development/cakephp2-php8/lib/Cake/Network/CakeRequest.php on line 1149
PHP Fatal error:  Uncaught Error: Class 'CakeRequest' not found in /Users/blahblah/development/cakephp2-php8/lib/Cake/I18n/L10n.php:433
Stack trace:
#0 /Users/blahblah/development/cakephp2-php8/lib/Cake/I18n/L10n.php(371): L10n->_autoLanguage()
#1 /Users/blahblah/development/cakephp2-php8/lib/Cake/I18n/I18n.php(221): L10n->get(NULL)
#2 /Users/blahblah/development/cakephp2-php8/lib/Cake/basics.php(636): I18n::translate('%s in [%s, line...', NULL, 'cake_console')
#3 /Users/blahblah/development/cakephp2-php8/lib/Cake/Console/ConsoleErrorHandler.php(83): __d('cake_console', '%s in [%s, line...', 'Declaration of ...', '/Users/blahblah/...', 1149)
#4 /Users/blahblah/development/cakephp2-php8/lib/Cake/Core/App.php(970): ConsoleErrorHandler->handleError(64, 'Declaration of ...', '/Users/blahblah/...', 1149, Array)
#5 /Users/blahblah/development/cakephp2-php8/lib/Cake/Core/App.php(943): App::_checkFatalError()
#6 [internal function]: App::shutdown()
#7 {main}
  thrown in /Users/blahblah/development/cakephp2-php8/lib/Cake/I18n/L10n.php on line 433

Fatal error: Uncaught Error: Class 'CakeRequest' not found in /Users/blahblah/development/cakephp2-php8/lib/Cake/I18n/L10n.php:433
Stack trace:
#0 /Users/blahblah/development/cakephp2-php8/lib/Cake/I18n/L10n.php(371): L10n->_autoLanguage()
#1 /Users/blahblah/development/cakephp2-php8/lib/Cake/I18n/I18n.php(221): L10n->get(NULL)
#2 /Users/blahblah/development/cakephp2-php8/lib/Cake/basics.php(636): I18n::translate('%s in [%s, line...', NULL, 'cake_console')
#3 /Users/blahblah/development/cakephp2-php8/lib/Cake/Console/ConsoleErrorHandler.php(83): __d('cake_console', '%s in [%s, line...', 'Declaration of ...', '/Users/blahblah/...', 1149)
#4 /Users/blahblah/development/cakephp2-php8/lib/Cake/Core/App.php(970): ConsoleErrorHandler->handleError(64, 'Declaration of ...', '/Users/blahblah/...', 1149, Array)
#5 /Users/blahblah/development/cakephp2-php8/lib/Cake/Core/App.php(943): App::_checkFatalError()
#6 [internal function]: App::shutdown()
#7 {main}
  thrown in /Users/blahblah/development/cakephp2-php8/lib/Cake/I18n/L10n.php on line 433

Fix running tests of framework

Cake's test relay hevily on PHPUnit_Test_Case class which comes from old version of PHPUnit.

  • Check how many deprecation notices show up in logs.
  • Investigate effort to update PHPUnit and all tests
  • Check how much effort costs upgrading PHPUnit. Requred version of PHPUnit is 8. In previous versions of PHPUnit there is each() used which is removed in PHP 8.

Bootstrap file

Check if it helps to run tests of framework: cakephp/cakephp#12700 (comment)

Undefined TESTS constants cause the "cake bake project" command to exit with an error

Description

The command cake bake project, which creates a project for a CakePHP 2 app, fails in PHP 8.0+ due to an undefined TESTS constant.
< PHP 8.0, it worked with a warning.

This bug occurs when executing the command before the project is generated:

vendor/bin/cake bake project โ€ฆ

but not when executing the command after it is generated:

app/Console/cake bake project โ€ฆ

Currently, there is almost no opportunity to create a new CakePHP 2 project. However, I would like to fix this command because I use it in the following situations.

  • Generate a project in CI step of the plugin repository
  • Show the steps to reproduce defects

How to reproduce the defect

$ mkdir new_project && cd new_project
$ composer init -n --name=acme/example --type=project  
Writing ./composer.json
$ composer config repositories.cakephp/cakephp vcs https://github.com/kamilwylegala/cakephp2-php8
$ composer require "cakephp/cakephp":"dev-master as 2.10.24"
$ yes y | vendor/bin/cake bake project test_app 
Error: Undefined constant "TESTS"
#0 /var/www/new_project/vendor/cakephp/cakephp/lib/Cake/Console/Shell.php(508): TaskCollection->load('Test', Array)
#1 /var/www/new_project/vendor/cakephp/cakephp/lib/Cake/Console/Command/BakeShell.php(242): Shell->__get('Test')
#2 /var/www/new_project/vendor/cakephp/cakephp/lib/Cake/Console/Shell.php(430): BakeShell->getOptionParser()
#3 /var/www/new_project/vendor/cakephp/cakephp/lib/Cake/Console/ShellDispatcher.php(222): Shell->runCommand('project', Array)
#4 /var/www/new_project/vendor/cakephp/cakephp/lib/Cake/Console/ShellDispatcher.php(66): ShellDispatcher->dispatch()
#5 /var/www/new_project/vendor/cakephp/cakephp/lib/Cake/Console/cake.php(54): ShellDispatcher::run(Array)
#6 {main}

PHP Version

  • PHP 8.0.27

Temporary workaround

Create temporary TESTS const in TestTask in the vendor directory.

hasAndBelongsToMany Relationships Not Working as Intended

When using a 'contain' parameter on a model find() operation, using a model that's associated with a hasAndBelongsToMany returns 0 associated entities, even when such an entity exists. Reading the database log, it's apparent that the correct query is running, and the database results contain the valid entity relationships but nothing is bound to the entities in CakePHP. This is using MySQL 5.7.38 and PHP 8.1.2. I've verified that the same thing is happening for a few different models. Other types of relationships are working fine, e.g. contain against a hasMany works as expected.

Here's an example from a model called User.

public $hasAndBelongsToMany = array(
        'Committee' => array(
            'className'  => 'Committee',
            'joinTable'  => 'committees_users',
            'foreignKey' => 'user_id',
            'associationForeignKey' => 'committee_id',
            'unique'     => true
        )
 );

And running the query like this:

    $user = $this->User->find('first', array(
        'contain'=>array('Committee'),
        'conditions'=>array('id'=>$some_id)
    ));

Relative time may not be cached if specified in CacheHelper duration

This Issue summarizes the details of the defects for the tests marked as incomplete in #23.
89fc8c9

Description

When using CacheHelper to cache views, if specify a relative time for duration, the view may not be cached in PHP 8.0+.

How to reproduce the defect

Follow the steps in CacheHelper - 2.x (Using the Helper) to make the cache available.
Next, create the controller and template.

app/Controller/PostsController.php

<?php
App::uses('AppController', 'Controller');

class PostsController extends AppController {
    public $uses = array();
    public $helpers = array('Cache');

    // Shorthand notation for specifying the same duration for all actions.
    public $cacheAction = '+10 seconds';

    public function index() {}
}

app/View/Posts/index.ctp

cached at <?= date('H:i:s'); ?>

Then go to http://webserver/posts.
If you reload the page repeatedly, the time display should not change for 10 seconds, but it does.

PHP Version

8.0.27

Temporary workaround

Can work around this by specifying the following in the duration.

  • $cacheAction = 10; (Specified by integer)
  • $cacheAction = '10 seconds' (Specify in a relative time string such that it begins with a number)

Security Patches

After pulling in this fork to our project, we've received dependabot alerts regarding a couple CakePHP2 vulnerabilities, notably:

CakePHP 2.x and 3.x before 3.1.5 might allow remote attackers to bypass the CSRF protection mechanism via the _method parameter.

I realize the scope of this project is to provide the minimal set of patches to meet compatibility with PHP8. But I wanted to inquire if there was any potential roadmap for patching issues like this, or if perhaps this has already been done? Thanks.

Fix Shell ReflectionMethod::__construct default null argument in hasMethod

On CakePHP's Shell commands, the default behavior is to run the mainfunction when either a method is not provided when executed which is failing when running the code on PHP 8.1.

With PHP 8.1, the ReflectionMethod __construct expects the $method argument to be string when an object is passed as the first parameter.

The problem found in the CakePHP code is that when a Shell command is called without the method to execute, the method is sent as NULL, causing the following error:

# ./app/Console/cake Foo
Error: ReflectionMethod::__construct(): Argument #2 ($method) cannot be null when argument #1 ($objectOrMethod) is an object
#0 /var/www/html/lib/Cake/Console/Shell.php(358): ReflectionMethod->__construct(Object(FooShell), NULL)
#1 /var/www/html/lib/Cake/Console/Shell.php(423): Shell->hasMethod(NULL)
#2 /var/www/html/lib/Cake/Console/ShellDispatcher.php(222): Shell->runCommand(NULL, Array)
#3 /var/www/html/lib/Cake/Console/ShellDispatcher.php(66): ShellDispatcher->dispatch()
#4 /var/www/html/app/Console/cake.php(47): ShellDispatcher::run(Array)
#5 {main}

PaginatorHelper::numbers() renders extra separator string

This Issue summarizes the details of the defects for the tests marked as incomplete in #23
a597f35

Description

When using PaginatorHelper::numbers() to create page number links, if $option['last'] is a label string instead of an offset number, an extra separator string is output.

How to reproduce the defect

Creata table, insert records, and PHP codes

Because the code is long, it is folded in <details>.

Details

Create posts table and insert data

The INSERT statement is executed many times until there are 30+ records.

CREATE DATABASE IF NOT EXISTS cakephp;

CREATE TABLE IF NOT EXISTS posts
(
    id       INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    title    VARCHAR(50),
    body     TEXT,
    created  DATETIME NOT NULL
);

-- The INSERT statement is executed many times until there are 30 or more records.
INSERT INTO posts (title, body, created)
VALUES
    ('The title', 'This is the post body.', NOW()),
    ('A title once again', 'And the post body follows.', NOW()),
    ('Title strikes back', 'This is really exciting! Not.', NOW())
;

app/Config/database.php

<?php
class DATABASE_CONFIG {
    public $default = array(
        'datasource' => 'Database/Mysql',
        'host' => 'dev-db',
        'login' => 'root',
        'password' => 'root',
        'database' => 'cakephp',
    );
}

app/Controller/PostsController.php

<?php  
App::uses('AppController', 'Controller');  
  
class PostsController extends AppController {  
   public $uses = array('Post');  
   public $components = array('Paginator');  
   public $paginate = array(  
      'limit' => 2,  
      'order' => array('Post.id' => 'asc')  
   );  
  
   public function index() {  
      $this->Paginator->settings = $this->paginate;  
      $posts = $this->Paginator->paginate('Post');  
      $this->set('posts', $posts);  
   }  
}

app/View/Posts/index.ctp

<h2>Posts</h2>  
<?php foreach ($posts as $post) { ?>  
<dl><dt><?= h($post['Post']['title']) ?></dt><dd><?= h($post['Post']['body']) ?></dd></dl>  
<?php } ?>  
<h3>Defect example (1)</h3>  
<h4>Code:</h4>  
<pre>$this-&gt;Paginator-&gt;numbers(true);</pre>  
<?php  
// The preceding code is shorthand for the following code.  
// $this->Paginator->numbers(array(  
//      'before' => ' | ', 'after' => ' | ', 'first' => 'first', 'last' => 'last'  
// ));  
?>  
<h4>output:</h4>  
<p><?= $this->Paginator->numbers(true) ?></p>  
  
<h3>Defect example (2): Explicitly specify labels</h3>  
<h4>code:</h4>  
<pre>$this-&gt;Paginator-&gt;numbers(  
   array('before' => ' | ', 'after' => ' | ', 'first' => 'First page', 'last' => 'Last page'));</pre>  
<h4>output:</h4>  
<p><?= $this->Paginator->numbers(array(  
      'before' => ' | ', 'after' => ' | ', 'first' => 'First page', 'last' => 'Last page'  
   )) ?></p>

View the page in web browser

When you access http://webserver/posts/index/page:8, your web browser will display the following

image

PHP Version

8.0.27

Temporary workaround

There may be no easy way to do this...
Add a helper class that extends PaginatorHelper to app/View/Helper (e.g. as AppPaginatorHelper) and modify numbers() as in #30.
Then, in the $helpers of the controller you want to use
Define it to be available under the alias Paginator.

    public $helpers = array(
        'Paginator' => array(
            'className' => 'AppPaginator'
        )
    );

ref: https://book.cakephp.org/2/en/views/helpers.html#using-and-configuring-helpers

On PHP 7.3 instead of 7.4 OK?

Not really an issue, but an question...

The readme says:

Only prerequisite is to have your application already on PHP 7.4.

Do you think it will work if the application is on PHP 7.3? I ask because for the version of Linux I'm using, the yum repository only has PHP 7.3 as the latest 7.x available, and I don't want to build PHP 7.4 from scratch if I don' t have to...

Advice?

Remove mixed type to avoid PHP 8.0+ features

Since in some of the cases this will be used to do the transition from older PHP versions, it will be better for the changes done to not use features included only in PHP8 or above.

One example of this is the mixed type, which was introduced on PHP 8, which is now being used in some of the methods like here

The reason for this request is to prevent adding changes which will force developers into PHP 8, since this is mostly going to help developers transitioning from an older version while they prepare the complete application. These covers scenarios such as:

  • Running the upgrade project in a pre-PHP 8 server for testing.
  • Having a release of the code on any server running an older version before the PHP upgrade.

It could benefit developers to be able to use this with a version prior to PHP 8 in case the applications they have to migrate are huge and could take time to be fully done, but they want to start testing with the new version.

Custom RouteClasses

When using custom route classes and passing back a controller and action parameter to direct the page to the correct controller/action, it thinks the controller and action don't exist.

notEmpty() deprecated

Hello,

First massive thanks for your work.
Maybe deprecated function are not the priority and even won't be solved in the future.
I'm not sure if i have the skills to contribute so maybe i'll let more qualidifed people to solve this if possible.

Deprecated (16384): Validation::notEmpty() is deprecated. Use Validation::notBlank() instead. [CORE/Cake/Utility/Validation.php, line 60]

Best,

Resolve PHP deprecation warnings

There are many deprecation errors which are suppressed. Suppressing the errors is a viable solution for production, however overall it does not seem like a good practice.

If you turn the error reporting on, there is many errors like the following one: strlen(): Passing null to parameter #1 ($string) of type string is deprecated on every page.

Removing all of the errors might be tedious work but I want to focus on resolving at least the most common.

Deeper explanation / motivation

We have old Cake app that we want to gradually migrate to newever version and in the process we are cutting the monolithic app into pieces, some of them running on different technologies, some of them running on Cake2. We prefer to have the deprecation errors ON because some of the code we are writing now is framework-agnostic and will be ported to more modern tech stack in the future (even PHP9 hopefully) so we want to write the code in a future-proof way. However having dozens of deprecation warnings from Cake2 printed all the time makes this quite uneasy.

Disclaimer

As this is my first issue & PR here, I woud also like to say hi & massive thank you to the author for creating this fork.

Regarding this issue itself, I already have the changes on my machine and will create PR in a moment. I know this issue is very general but I hope to iterate upon this matter and resolve moste of the errors over time as it seems the most convenient way.

my project in 2.9.8(cakephp) traying to upgrade to php8.. getting error

Uncaught Error: Unknown named parameter $subject in

app/Vendor/cakephp/cakephp/lib/Cake/Utility/ObjectCollection.php:128 Stack trace: #0 app/Vendor/cakephp/cakephp/lib/Cake/Event/CakeEventManager.php(243): ObjectCollection->trigger() #1 app/Vendor/cakephp/cakephp/lib/Cake/Controller/Controller.php(677): CakeEventManager->dispatch() #2 app/Vendor/cakephp/cakephp/lib/Cake/Error/ExceptionRenderer.php(158): Controller->startupProcess() #3 app/Vendor/cakephp/cakephp/lib/Cake/Error/ExceptionRenderer.php(95): ExceptionRenderer->_getController() #4 app/Vendor/cakephp/cakephp/lib/Cake/Error/ErrorHandler.php(126): ExceptionRenderer->__construct() #5 app/Vendor/cakephp/cakephp/lib/Cake/Error/ErrorHandler.php(269): ErrorHandler::handleException() #6 pp/Vendor/cakephp/cakephp/lib/Cake/Error/ErrorHandler.php(212): ErrorHandler::handleFatalError() #7 app/Vendor/cakephp/cakephp/lib/Cake/Core/App.php(970): ErrorHandler::handleError() #8 app/Vendor/cakephp/cakephp/lib/Cake/Core/App.php(943): App::_checkFatalError() #9 [internal function]: App::shutdown() #10 {main} thrown in app/Vendor/cakephp/cakephp/lib/Cake/Utility/ObjectCollection.php on line 128

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.