Skip to content

Commit

Permalink
NTO-180 PHP8.1 compatibility (#5)
Browse files Browse the repository at this point in the history
* Fix tests to be able to finish it without a fatal error

Execute record generator related test first

* Fix tests for relationship fetch order when the order is not explicitly set on the query

* Fix PHP 7 compatibility about deep isset() on class that implement ArrayAccess

Fix comments for record filter

* Mark as known bug, integer validation with numbers greater than PHP_INT_MAX

* Fix test for export to XML

* Fix PHP 7.4 compatibility

* Add zlib required PHP extension on composer configuration

* Fix code structure about always close connections after each test

Co-authored-by: Emanuele Panzeri <thepanz@gmail.com>

* Add consistent local environment for testing with docker and docker-compose (FriendsOfSymfony1#86)

Related to FriendsOfSymfony1/symfony1#261

Co-authored-by: Emanuele Panzeri <thepanz@gmail.com>

* Update Builder.php for PHP8 compatibility (FriendsOfSymfony1#82)

Fix mandatory value for array $emittedActAs (PHP 8 compatibility)

* imported double-quoting changes from zikula/doctrine1@bda84a8

* Applied patches from JSB-363 (#1)

* JSB-363: Added missing calls to applyIndexes when considering subqueries/raw SQL (#3)

* Added missing calls for applying indexes to subsuqeries and rawSql queries

* query execution now solely depeneds on getSqlQuery

* Removed redundant binding of indexes to a cached query

* PHP 8.1 > Automatic conversion of false to array is deprecated
Fix Doctrine_Record _invokedSaveHooks cannot assign array value to boolean
Declaration to array instead of boolean

* PHP 8.1 > Serializable Phase Out
https://wiki.php.net/rfc/phase_out_serializable

PHP 7.4 add a new Serialize mecanism
PHP 8.1 made old method, "Serializable implementation" deprecated
PHP 9.0 (no release date at this moment) will drop the support.

Temporary Fix: Adding both method serialize/unserialize and __serialize/__unserialize

In order to be compatible with future PHP 9.0, once it will be release, we will have to drop the support to PHP Version before 7.4.

Currently a lot of Unix distribution in LTS are running a PHP Version older than 7.4 so moving to the final solution of "add return type" should break a lot of setup for the moment.

* PHP 8.0 > Typing of internal function parameters do not allow null value anymore.

Method str_replace/strtotime now require a string, not null

FIX: PDOStatement::fetch, $cursorOffset must be a int
Doctrine_Connection_Statement->fetch() default value to null

FIX: Private methods cannot be final as they are never overridden by other classes
Doctrine_Query_Having->_parseAliases(), remove "final"

* PHP 8.1 > internal_method_return_types
https://wiki.php.net/rfc/internal_method_return_types

PHP 8.0 added return type for abstract methods on Iterator, ArrayAccess, Countable, IteratorAggregate
PHP 8.1 made non implementation as a Deprecated Warning
PHP 9.0 (no release date at this moment) will drop the support.

Temporary Fix : adding this Attribute
Will drop the Deprecated warning.

Adding return type will break compatibility before PHP 7.4,
Return type has been added on PHP 7.0, but "mixed" special type is required, and it has been added on PHP 7.4.
In order to be compatible with future PHP 9.0, once it will be release, we will have to drop the support to PHP Version before 7.4

Currently a lot of Unix distribution in LTS are running a PHP Version older than 7.4 so moving to the final solution of "add return type" should break a lot of setup for the moment.

Add missing Annotation

* Update Travis to PHP up to 8.1
Php5.3 is broken due to Letsencrypt certificate cannot download composer

* PHP 8.0 > Doctrine_Query:36, uncaught TypeError: Unsupported operand types: string % int

Doctrine_Parser_Xml:89, htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated

https://wiki.php.net/rfc/internal_method_return_types for
Doctrine_Node
Doctrine_Adapter_Mock
Doctrine_EventListener_TestLogger
Doctrine_Parser_Xml

Doctrine_Ticket_1254_TestCase, replace stftime() by date() with format adaptation.

* PHP 8.1 fix last
sfYamlInline, backport fix from Symfony1.

Doctrine_Hydrator_Graph fix array_map, rtrim(): Passing null to parameter #1 ($string) of type string is deprecated
I emmit the hypothese that this array_map was broken, because array_map result is not assigned.

Doctrine_Migration_Diff:333, str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated

Doctrine_Migration_Builder:78:, is_dir(): Passing null to parameter #1 ($filename) of type string is deprecated

Doctrine_Validator_Notblank, allow null value
HydrationListener, in HydrateTestCase.php, fix strtoupper(): Passing null to parameter #1 ($string) of type string is deprecated

internal_method_return_types
https://wiki.php.net/rfc/internal_method_return_types
see 2b2d173 for details
Doctrine_Collection_OnDemand
Doctrine_Validator_Exception

* Fix test 1783 - 64bit compatibility
On 32 bit system, PHP use a float to overflow a bigint.
On 64 bit, PHP int is the same as a database bigint, so this test is not relevant anymore

* PHP 8.1 PDO stringify is now disable by default.

Activate it for Mysql + Sqlite
https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.mysql

* PHP8.1 Fix: Warning: strtotime() : Epoch doesn't fit in a PHP integer in Doctrine_Record.
This is only happening on 32bit system, because int 32bit could not map the whole strtotime date scope.
Example value: "0000-00-00 00:00:00"
Before 8.1 strtotime returns false, after it return false but also raise a Warning.
@ is slightly lowering performance, it should not trigger any unwanted error, as if format is invalid strtotime should return "false"
As this old project need BC for old system, seems the best fix.

* Annotate can return null

Co-authored-by: Emanuele Panzeri <thepanz@gmail.com>

* Return annotation

Co-authored-by: Emanuele Panzeri <thepanz@gmail.com>

* Return annotation

Co-authored-by: Emanuele Panzeri <thepanz@gmail.com>

* Coding style

And remove an useless return false

Co-authored-by: Emanuele Panzeri <thepanz@gmail.com>
Co-authored-by: Thomas <th@it-solutions-hirsch.de>

* Fix annotation.
Remove Doctrine_Table::findBy* and findByOne* which are not phpdoc valid.
Each class "MyTable" which "Doctrine_Table" should have all magick @method declared

Fix invalid annotation and remove blank lines

* Remove useless string cast by testing null before

* Fix SQLite Connect to return a boolean

* Fix BC compatibility for any dev using fetch($currentOffset = null)

* Commit Suggestions - Fix phpDoc and yoda style

Thanks to thePanz and Alquerci !

Co-authored-by: Alexandre Quercia <alquerci@email.com>
Co-authored-by: Emanuele Panzeri <thepanz@gmail.com>

* Handle default taskName to null, to avoid triggering the strlen(null) php 8.1 incompatibility

* Fix taskname empty length

Co-authored-by: Emanuele Panzeri <thepanz@gmail.com>

* bumped min php version, bumped branch alias

* don't attempt `strtolower` on null values

* updated iterator method signatures to match upstream

* avoid returning any value from a `: void` hinted function

* PHP 8.0 > Typing of internal function parameters do not allow null value anymore.

Method str_replace/strtotime now require a string, not null

FIX: PDOStatement::fetch, $cursorOffset must be a int
Doctrine_Connection_Statement->fetch() default value to null

FIX: Private methods cannot be final as they are never overridden by other classes
Doctrine_Query_Having->_parseAliases(), remove "final"

* PHP 8.1 > Compatibility
sfYamlInline, backport fix from Symfony1.

Doctrine_Hydrator_Graph fix array_map, rtrim(): Passing null to parameter #1 ($string) of type string is deprecated
I emmit the hypothese that this array_map was broken, because array_map result is not assigned.

Doctrine_Migration_Diff:333, str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated

Doctrine_Migration_Builder:78:, is_dir(): Passing null to parameter #1 ($filename) of type string is deprecated

Doctrine_Validator_Notblank, allow null value
HydrationListener, in HydrateTestCase.php, fix strtoupper(): Passing null to parameter #1 ($string) of type string is deprecated

internal_method_return_types
https://wiki.php.net/rfc/internal_method_return_types
see 2b2d173 for details
Doctrine_Collection_OnDemand
Doctrine_Validator_Exception

PHP 8.1 PDO stringify is now disable by default.

Activate it for Mysql + Sqlite
https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.mysql

PHP 8.1 Fix: Warning: strtotime() : Epoch doesn't fit in a PHP integer in Doctrine_Record.
This is only happening on 32bit system, because int 32bit could not map the whole strtotime date scope.
Example value: "0000-00-00 00:00:00"
Before 8.1 strtotime returns false, after it return false but also raise a Warning.
@ is slightly lowering performance, it should not trigger any unwanted error, as if format is invalid strtotime should return "false"
As this old project need BC for old system, seems the best fix.

PHP 8.1 > Automatic conversion of false to array is deprecated
Fix Doctrine_Record _invokedSaveHooks cannot assign array value to boolean
Declaration to array instead of boolean

PHP 8.1 > Serializable Phase Out
https://wiki.php.net/rfc/phase_out_serializable

PHP 7.4 add a new Serialize mecanism
PHP 8.1 made old method, "Serializable implementation" deprecated
PHP 9.0 (no release date at this moment) will drop the support.

Temporary Fix: Adding both method serialize/unserialize and __serialize/__unserialize

In order to be compatible with future PHP 9.0, once it will be release, we will have to drop the support to PHP Version before 7.4.

Currently a lot of Unix distribution in LTS are running a PHP Version older than 7.4 so moving to the final solution of "add return type" should break a lot of setup for the moment.

PHP 8.1 > internal_method_return_types
https://wiki.php.net/rfc/internal_method_return_types

PHP 8.0 added return type for abstract methods on Iterator, ArrayAccess, Countable, IteratorAggregate
PHP 8.1 made non implementation as a Deprecated Warning
PHP 9.0 (no release date at this moment) will drop the support.

Temporary Fix : adding this Attribute
Will drop the Deprecated warning.

Adding return type will break compatibility before PHP 7.4,
Return type has been added on PHP 7.0, but "mixed" special type is required, and it has been added on PHP 7.4.
In order to be compatible with future PHP 9.0, once it will be release, we will have to drop the support to PHP Version before 7.4

Currently a lot of Unix distribution in LTS are running a PHP Version older than 7.4 so moving to the final solution of "add return type" should break a lot of setup for the moment.

Update Travis to PHP up to 8.1

PHP 8.0 > Doctrine_Query:36, uncaught TypeError: Unsupported operand types: string % int

Doctrine_Parser_Xml:89, htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated

https://wiki.php.net/rfc/internal_method_return_types for
Doctrine_Node
Doctrine_Adapter_Mock
Doctrine_EventListener_TestLogger
Doctrine_Parser_Xml

Doctrine_Ticket_1254_TestCase, replace stftime() by date() with format adaptation.

* PR Review - Small bug Fixes

Fix BC compatibility for any dev using fetch($currentOffset = null)
Fix SQLite Connect to return a boolean
Remove useless string cast by testing null before
Check TaskName declaration

Fix test 1783 - 64bit compatibility
On 32 bit system, PHP use a float to overflow a bigint.
On 64 bit, PHP int is the same as a database bigint, so this test is not relevant anymore

* Fix Annotation and Coding Style

* Add proof tast name with empty task name property sets by child class

* minor PSR fixes

* minor tidies suggested at code review

* removed docker environments for testing older php versions

Co-authored-by: Alexandre Quercia <alquerci@email.com>
Co-authored-by: Emanuele Panzeri <thepanz@gmail.com>
Co-authored-by: xNatek <nathan.trenet@gmail.com>
Co-authored-by: Alexander Sims <alexmk92@live.co.uk>
Co-authored-by: Tybaze <tybaze@users.noreply.github.com>
Co-authored-by: Ben Tybaze <6998932+Tybaze@users.noreply.github.com>
Co-authored-by: Thomas <th@it-solutions-hirsch.de>
  • Loading branch information
8 people committed Jul 4, 2024
1 parent b115c58 commit e549dd6
Show file tree
Hide file tree
Showing 26 changed files with 168 additions and 267 deletions.
34 changes: 34 additions & 0 deletions .docker/php74_81/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
ARG PHP_VERSION
FROM php:${PHP_VERSION}-cli

RUN docker-php-ext-install pdo
RUN docker-php-ext-install pdo_mysql

# Install mbstring PHP extension
#
RUN set -eux; \
apt-get update; \
apt-get install -y --no-upgrade --no-install-recommends \
libonig-dev \
; \
\
apt-get clean; \
rm -rf /var/lib/apt/lists/*; \
\
docker-php-ext-install mbstring

# For consistent mime type file guesser
RUN set -eux; \
distFilePath=`which file`; \
\
mv ${distFilePath} ${distFilePath}.dist; \
{ \
echo '#! /bin/sh -eu'; \
echo ''; \
echo "${distFilePath}"'.dist "$@" | sed -e s,application/x-pie-executable,application/x-executable,g'; \
} | tee ${distFilePath}; \
\
chmod +x ${distFilePath}; \
\
file /bin/ls --mime | grep application/x-executable; \
:;
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Installation

Using [Composer](http://getcomposer.org/doc/00-intro.md) as dependency management:

composer require friendsofsymfony1/doctrine1 "1.4.*"
composer require james-and-james-fulfilment/doctrine1 "1.5.*"
composer install


Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"ext-iconv": "*",
"php": ">=8.1",
"ext-mbstring": "*",
"ext-pdo": "*",
"ext-zlib": "*"
Expand All @@ -37,7 +36,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
"dev-php81": "1.5-dev"
}
},
"config": {
Expand Down
96 changes: 4 additions & 92 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,11 @@ services:
- |
exec tail -f /dev/null
php53:
build: .docker/php53
working_dir: /app/tests
volumes:
- .:/app
- db_socket:/var/run/mysqld
entrypoint:
- sh
- -c
- |
{
echo 'pdo_mysql.default_socket = /var/run/mysqld/mysql.sock'
echo 'memory_limit = -1'
echo 'short_open_tag = off'
echo 'magic_quotes_gpc = off'
echo 'date.timezone = "UTC"'
} | tee -a /usr/local/lib/php.ini
exec tail -f /dev/null
php54: &services_php54
php81:
build:
context: .docker/php54
context: .docker/php74_81
args:
PHP_VERSION: '8.1'
working_dir: /app/tests
volumes:
- .:/app
Expand All @@ -58,76 +40,6 @@ services:
depends_on:
- db

php55:
<<: *services_php54
build:
context: .docker/php55_71
args:
PHP_TAG: '5.5-cli'

php56:
<<: *services_php54
build:
context: .docker/php55_71
args:
PHP_TAG: '5.6-cli-jessie'

php70:
<<: *services_php54
build:
context: .docker/php55_71
args:
PHP_TAG: '7.0-cli-jessie'

php71:
<<: *services_php54
build:
context: .docker/php55_71
args:
PHP_TAG: '7.1-cli-jessie'

php72:
<<: *services_php54
build:
context: .docker/php72_73
args:
PHP_VERSION: '7.2'

php73:
<<: *services_php54
build:
context: .docker/php72_73
args:
PHP_VERSION: '7.3'

php74:
<<: *services_php54
build:
context: .docker/php74_82
args:
PHP_VERSION: '7.4'

php80:
<<: *services_php54
build:
context: .docker/php74_82
args:
PHP_VERSION: '8.0'

php81:
<<: *services_php54
build:
context: .docker/php74_82
args:
PHP_VERSION: '8.1'

php82:
<<: *services_php54
build:
context: .docker/php74_82
args:
PHP_VERSION: '8.2'

db:
image: mysql:5.5.62
environment:
Expand Down
10 changes: 5 additions & 5 deletions lib/Doctrine/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function __construct($table, $keyColumn = null)
}

if ($keyColumn === null) {
$keyColumn = $table->getAttribute(Doctrine_Core::ATTR_COLL_KEY);
$keyColumn = $table->getAttribute(Doctrine_Core::ATTR_COLL_KEY);
}

if ($keyColumn !== null) {
Expand Down Expand Up @@ -152,15 +152,15 @@ public function serialize()
{
$vars = $this->__serialize();

return serialize($vars);
return $vars;
}

/**
* This method is automatically called everytime a Doctrine_Collection object is unserialized
* Unserializes a Doctrine_Collection instance for php 7.4+
*
* @return void
* @param string $serialized A serialized Doctrine_Collection instance
*/
public function unserialize($serialized)
public function __unserialize($data)
{
$array = unserialize($serialized);

Expand Down
14 changes: 5 additions & 9 deletions lib/Doctrine/Collection/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public function __construct($collection)
*
* @return void
*/
#[\ReturnTypeWillChange]
public function rewind()
public function rewind(): void
{
$this->index = 0;
$i = $this->index;
Expand All @@ -89,8 +88,7 @@ public function rewind()
*
* @return integer
*/
#[\ReturnTypeWillChange]
public function key()
public function key(): mixed
{
return $this->key;
}
Expand All @@ -100,8 +98,7 @@ public function key()
*
* @return Doctrine_Record
*/
#[\ReturnTypeWillChange]
public function current()
public function current(): mixed
{
return $this->collection->get($this->key);
}
Expand All @@ -111,13 +108,12 @@ public function current()
*
* @return void
*/
#[\ReturnTypeWillChange]
public function next()
public function next(): void
{
$this->index++;
$i = $this->index;
if (isset($this->keys[$i])) {
$this->key = $this->keys[$i];
}
}
}
}
19 changes: 7 additions & 12 deletions lib/Doctrine/Collection/OnDemand.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ private function _hydrateCurrent()
}
}

#[\ReturnTypeWillChange]
public function rewind()
public function rewind(): void
{
$this->index = 0;
$this->_stmt->closeCursor();
Expand All @@ -74,32 +73,28 @@ public function rewind()
$this->_hydrateCurrent();
}

#[\ReturnTypeWillChange]
public function key()
public function key(): mixed
{
return $this->index;
}

#[\ReturnTypeWillChange]
public function current()
public function current(): mixed
{
return $this->_current;
}

#[\ReturnTypeWillChange]
public function next()
public function next(): void
{
$this->_current = null;
$this->index++;
$this->_hydrateCurrent();
}

#[\ReturnTypeWillChange]
public function valid()
public function valid(): bool
{
if ( ! is_null($this->_current) && $this->_current !== false) {
if (!is_null($this->_current) && $this->_current !== false) {
return true;
}
return false;
}
}
}
24 changes: 12 additions & 12 deletions lib/Doctrine/Connection/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class Doctrine_Connection_Profiler implements Doctrine_Overloadable, IteratorAgg
/**
* constructor
*/
public function __construct() {

public function __construct()
{
}

/**
Expand All @@ -67,9 +67,10 @@ public function __construct() {
* @param integer $filter
* @return boolean
*/
public function setFilterQueryType() {

public function setFilterQueryType()
{
}

/**
* method overloader
* this method is used for invoking different listeners, for the full
Expand All @@ -83,7 +84,7 @@ public function setFilterQueryType() {
public function __call($m, $a)
{
// first argument should be an instance of Doctrine_Event
if ( ! ($a[0] instanceof Doctrine_Event)) {
if (!($a[0] instanceof Doctrine_Event)) {
throw new Doctrine_Connection_Profiler_Exception("Couldn't listen event. Event should be an instance of Doctrine_Event.");
}

Expand All @@ -93,7 +94,7 @@ public function __call($m, $a)
$a[0]->start();

$eventSequence = $a[0]->getSequence();
if ( ! isset($this->eventSequences[$eventSequence])) {
if (!isset($this->eventSequences[$eventSequence])) {
$this->events[] = $a[0];
$this->eventSequences[$eventSequence] = true;
}
Expand All @@ -109,7 +110,7 @@ public function __call($m, $a)
* @param mixed $key
* @return Doctrine_Event|null
*/
public function get($key)
public function get($key): ?Doctrine_Event
{
if (isset($this->events[$key])) {
return $this->events[$key];
Expand All @@ -123,7 +124,7 @@ public function get($key)
*
* @return Doctrine_Event[] All events in an array
*/
public function getAll()
public function getAll(): array
{
return $this->events;
}
Expand Down Expand Up @@ -156,11 +157,10 @@ public function count()
*
* @return Doctrine_Event|null
*/
public function pop()
public function pop(): ?Doctrine_Event
{
$event = array_pop($this->events);
if ($event !== null)
{
if ($event !== null) {
unset($this->eventSequences[$event->getSequence()]);
}
return $event;
Expand All @@ -181,4 +181,4 @@ public function lastEvent()
end($this->events);
return current($this->events);
}
}
}
4 changes: 2 additions & 2 deletions lib/Doctrine/Connection/Sqlite.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function connect()

$connected = parent::connect();

if(!$hasConfigureStringify) {
if (!$hasConfigureStringify) {
// PHP8.1 require default to true to keep BC
// https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.sqlite
// Can be overwritten by user later
Expand Down Expand Up @@ -144,4 +144,4 @@ public function dropDatabase()

$this->export->dropDatabase($info['database']);
}
}
}
Loading

0 comments on commit e549dd6

Please sign in to comment.