Skip to content

Commit e549dd6

Browse files
akhumphreyalquercithePanzxNatekAlexander Sims
committedJul 4, 2024
NTO-180 PHP8.1 compatibility (#5)
* 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>
1 parent b115c58 commit e549dd6

26 files changed

+168
-267
lines changed
 

‎.docker/php74_81/Dockerfile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
ARG PHP_VERSION
2+
FROM php:${PHP_VERSION}-cli
3+
4+
RUN docker-php-ext-install pdo
5+
RUN docker-php-ext-install pdo_mysql
6+
7+
# Install mbstring PHP extension
8+
#
9+
RUN set -eux; \
10+
apt-get update; \
11+
apt-get install -y --no-upgrade --no-install-recommends \
12+
libonig-dev \
13+
; \
14+
\
15+
apt-get clean; \
16+
rm -rf /var/lib/apt/lists/*; \
17+
\
18+
docker-php-ext-install mbstring
19+
20+
# For consistent mime type file guesser
21+
RUN set -eux; \
22+
distFilePath=`which file`; \
23+
\
24+
mv ${distFilePath} ${distFilePath}.dist; \
25+
{ \
26+
echo '#! /bin/sh -eu'; \
27+
echo ''; \
28+
echo "${distFilePath}"'.dist "$@" | sed -e s,application/x-pie-executable,application/x-executable,g'; \
29+
} | tee ${distFilePath}; \
30+
\
31+
chmod +x ${distFilePath}; \
32+
\
33+
file /bin/ls --mime | grep application/x-executable; \
34+
:;

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Installation
2020

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

23-
composer require friendsofsymfony1/doctrine1 "1.4.*"
23+
composer require james-and-james-fulfilment/doctrine1 "1.5.*"
2424
composer install
2525

2626

‎composer.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
}
2121
],
2222
"require": {
23-
"php": "^7.4 || ^8.0",
24-
"ext-iconv": "*",
23+
"php": ">=8.1",
2524
"ext-mbstring": "*",
2625
"ext-pdo": "*",
2726
"ext-zlib": "*"
@@ -37,7 +36,7 @@
3736
},
3837
"extra": {
3938
"branch-alias": {
40-
"dev-master": "1.4-dev"
39+
"dev-php81": "1.5-dev"
4140
}
4241
},
4342
"config": {

‎docker-compose.yml

+4-92
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,11 @@ services:
1515
- |
1616
exec tail -f /dev/null
1717
18-
php53:
19-
build: .docker/php53
20-
working_dir: /app/tests
21-
volumes:
22-
- .:/app
23-
- db_socket:/var/run/mysqld
24-
entrypoint:
25-
- sh
26-
- -c
27-
- |
28-
{
29-
echo 'pdo_mysql.default_socket = /var/run/mysqld/mysql.sock'
30-
echo 'memory_limit = -1'
31-
echo 'short_open_tag = off'
32-
echo 'magic_quotes_gpc = off'
33-
echo 'date.timezone = "UTC"'
34-
} | tee -a /usr/local/lib/php.ini
35-
36-
exec tail -f /dev/null
37-
38-
php54: &services_php54
18+
php81:
3919
build:
40-
context: .docker/php54
20+
context: .docker/php74_81
21+
args:
22+
PHP_VERSION: '8.1'
4123
working_dir: /app/tests
4224
volumes:
4325
- .:/app
@@ -58,76 +40,6 @@ services:
5840
depends_on:
5941
- db
6042

61-
php55:
62-
<<: *services_php54
63-
build:
64-
context: .docker/php55_71
65-
args:
66-
PHP_TAG: '5.5-cli'
67-
68-
php56:
69-
<<: *services_php54
70-
build:
71-
context: .docker/php55_71
72-
args:
73-
PHP_TAG: '5.6-cli-jessie'
74-
75-
php70:
76-
<<: *services_php54
77-
build:
78-
context: .docker/php55_71
79-
args:
80-
PHP_TAG: '7.0-cli-jessie'
81-
82-
php71:
83-
<<: *services_php54
84-
build:
85-
context: .docker/php55_71
86-
args:
87-
PHP_TAG: '7.1-cli-jessie'
88-
89-
php72:
90-
<<: *services_php54
91-
build:
92-
context: .docker/php72_73
93-
args:
94-
PHP_VERSION: '7.2'
95-
96-
php73:
97-
<<: *services_php54
98-
build:
99-
context: .docker/php72_73
100-
args:
101-
PHP_VERSION: '7.3'
102-
103-
php74:
104-
<<: *services_php54
105-
build:
106-
context: .docker/php74_82
107-
args:
108-
PHP_VERSION: '7.4'
109-
110-
php80:
111-
<<: *services_php54
112-
build:
113-
context: .docker/php74_82
114-
args:
115-
PHP_VERSION: '8.0'
116-
117-
php81:
118-
<<: *services_php54
119-
build:
120-
context: .docker/php74_82
121-
args:
122-
PHP_VERSION: '8.1'
123-
124-
php82:
125-
<<: *services_php54
126-
build:
127-
context: .docker/php74_82
128-
args:
129-
PHP_VERSION: '8.2'
130-
13143
db:
13244
image: mysql:5.5.62
13345
environment:

‎lib/Doctrine/Collection.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function __construct($table, $keyColumn = null)
9191
}
9292

9393
if ($keyColumn === null) {
94-
$keyColumn = $table->getAttribute(Doctrine_Core::ATTR_COLL_KEY);
94+
$keyColumn = $table->getAttribute(Doctrine_Core::ATTR_COLL_KEY);
9595
}
9696

9797
if ($keyColumn !== null) {
@@ -152,15 +152,15 @@ public function serialize()
152152
{
153153
$vars = $this->__serialize();
154154

155-
return serialize($vars);
155+
return $vars;
156156
}
157157

158158
/**
159-
* This method is automatically called everytime a Doctrine_Collection object is unserialized
159+
* Unserializes a Doctrine_Collection instance for php 7.4+
160160
*
161-
* @return void
161+
* @param string $serialized A serialized Doctrine_Collection instance
162162
*/
163-
public function unserialize($serialized)
163+
public function __unserialize($data)
164164
{
165165
$array = unserialize($serialized);
166166

‎lib/Doctrine/Collection/Iterator.php

+5-9
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ public function __construct($collection)
7474
*
7575
* @return void
7676
*/
77-
#[\ReturnTypeWillChange]
78-
public function rewind()
77+
public function rewind(): void
7978
{
8079
$this->index = 0;
8180
$i = $this->index;
@@ -89,8 +88,7 @@ public function rewind()
8988
*
9089
* @return integer
9190
*/
92-
#[\ReturnTypeWillChange]
93-
public function key()
91+
public function key(): mixed
9492
{
9593
return $this->key;
9694
}
@@ -100,8 +98,7 @@ public function key()
10098
*
10199
* @return Doctrine_Record
102100
*/
103-
#[\ReturnTypeWillChange]
104-
public function current()
101+
public function current(): mixed
105102
{
106103
return $this->collection->get($this->key);
107104
}
@@ -111,13 +108,12 @@ public function current()
111108
*
112109
* @return void
113110
*/
114-
#[\ReturnTypeWillChange]
115-
public function next()
111+
public function next(): void
116112
{
117113
$this->index++;
118114
$i = $this->index;
119115
if (isset($this->keys[$i])) {
120116
$this->key = $this->keys[$i];
121117
}
122118
}
123-
}
119+
}

‎lib/Doctrine/Collection/OnDemand.php

+7-12
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ private function _hydrateCurrent()
6464
}
6565
}
6666

67-
#[\ReturnTypeWillChange]
68-
public function rewind()
67+
public function rewind(): void
6968
{
7069
$this->index = 0;
7170
$this->_stmt->closeCursor();
@@ -74,32 +73,28 @@ public function rewind()
7473
$this->_hydrateCurrent();
7574
}
7675

77-
#[\ReturnTypeWillChange]
78-
public function key()
76+
public function key(): mixed
7977
{
8078
return $this->index;
8179
}
8280

83-
#[\ReturnTypeWillChange]
84-
public function current()
81+
public function current(): mixed
8582
{
8683
return $this->_current;
8784
}
8885

89-
#[\ReturnTypeWillChange]
90-
public function next()
86+
public function next(): void
9187
{
9288
$this->_current = null;
9389
$this->index++;
9490
$this->_hydrateCurrent();
9591
}
9692

97-
#[\ReturnTypeWillChange]
98-
public function valid()
93+
public function valid(): bool
9994
{
100-
if ( ! is_null($this->_current) && $this->_current !== false) {
95+
if (!is_null($this->_current) && $this->_current !== false) {
10196
return true;
10297
}
10398
return false;
10499
}
105-
}
100+
}

‎lib/Doctrine/Connection/Profiler.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class Doctrine_Connection_Profiler implements Doctrine_Overloadable, IteratorAgg
5757
/**
5858
* constructor
5959
*/
60-
public function __construct() {
61-
60+
public function __construct()
61+
{
6262
}
6363

6464
/**
@@ -67,9 +67,10 @@ public function __construct() {
6767
* @param integer $filter
6868
* @return boolean
6969
*/
70-
public function setFilterQueryType() {
71-
70+
public function setFilterQueryType()
71+
{
7272
}
73+
7374
/**
7475
* method overloader
7576
* this method is used for invoking different listeners, for the full
@@ -83,7 +84,7 @@ public function setFilterQueryType() {
8384
public function __call($m, $a)
8485
{
8586
// first argument should be an instance of Doctrine_Event
86-
if ( ! ($a[0] instanceof Doctrine_Event)) {
87+
if (!($a[0] instanceof Doctrine_Event)) {
8788
throw new Doctrine_Connection_Profiler_Exception("Couldn't listen event. Event should be an instance of Doctrine_Event.");
8889
}
8990

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

9596
$eventSequence = $a[0]->getSequence();
96-
if ( ! isset($this->eventSequences[$eventSequence])) {
97+
if (!isset($this->eventSequences[$eventSequence])) {
9798
$this->events[] = $a[0];
9899
$this->eventSequences[$eventSequence] = true;
99100
}
@@ -109,7 +110,7 @@ public function __call($m, $a)
109110
* @param mixed $key
110111
* @return Doctrine_Event|null
111112
*/
112-
public function get($key)
113+
public function get($key): ?Doctrine_Event
113114
{
114115
if (isset($this->events[$key])) {
115116
return $this->events[$key];
@@ -123,7 +124,7 @@ public function get($key)
123124
*
124125
* @return Doctrine_Event[] All events in an array
125126
*/
126-
public function getAll()
127+
public function getAll(): array
127128
{
128129
return $this->events;
129130
}
@@ -156,11 +157,10 @@ public function count()
156157
*
157158
* @return Doctrine_Event|null
158159
*/
159-
public function pop()
160+
public function pop(): ?Doctrine_Event
160161
{
161162
$event = array_pop($this->events);
162-
if ($event !== null)
163-
{
163+
if ($event !== null) {
164164
unset($this->eventSequences[$event->getSequence()]);
165165
}
166166
return $event;
@@ -181,4 +181,4 @@ public function lastEvent()
181181
end($this->events);
182182
return current($this->events);
183183
}
184-
}
184+
}

‎lib/Doctrine/Connection/Sqlite.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function connect()
9898

9999
$connected = parent::connect();
100100

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

145145
$this->export->dropDatabase($info['database']);
146146
}
147-
}
147+
}

0 commit comments

Comments
 (0)