Skip to content

Commit 50cb69e

Browse files
TybazethePanz
authored andcommitted
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 #[\ReturnTypeWillChange] 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.
1 parent 27943d7 commit 50cb69e

29 files changed

+243
-70
lines changed

.travis.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
os: linux
2-
dist: xenial
2+
dist: focal
33
language: php
44

55
php:
6-
- 7.0
7-
- 7.1
8-
- 7.2
9-
- 7.3
106
- 7.4
7+
- 8.0
8+
- 8.1
119
- nightly
1210

1311
cache:
@@ -18,15 +16,25 @@ jobs:
1816
fast_finish: true
1917
allow_failures:
2018
- php: nightly
19+
- php: 5.3
2120
include:
2221
- php: 5.3
2322
dist: precise
2423
- php: 5.4
25-
dist: precise
24+
dist: trusty
2625
- php: 5.5
2726
dist: trusty
2827
- php: 5.6
2928
dist: trusty
29+
- php: 7.0
30+
dist: xenial
31+
- php: 7.1
32+
dist: xenial
33+
- php: 7.2
34+
dist: xenial
35+
- php: 7.3
36+
dist: xenial
37+
3038

3139
services:
3240
- mysql

lib/Doctrine/Access.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function __isset($name)
8989
* @param string $name
9090
* @return void
9191
*/
92+
#[\ReturnTypeWillChange]
9293
public function __unset($name)
9394
{
9495
return $this->remove($name);
@@ -100,6 +101,7 @@ public function __unset($name)
100101
* @param mixed $offset
101102
* @return boolean Whether or not this object contains $offset
102103
*/
104+
#[\ReturnTypeWillChange]
103105
public function offsetExists($offset)
104106
{
105107
return $this->contains($offset);
@@ -112,6 +114,7 @@ public function offsetExists($offset)
112114
* @param mixed $offset
113115
* @return mixed
114116
*/
117+
#[\ReturnTypeWillChange]
115118
public function offsetGet($offset)
116119
{
117120
// array notation with no index was causing 'undefined variable: $offset' notices in php7,
@@ -131,6 +134,7 @@ public function offsetGet($offset)
131134
* @param mixed $value
132135
* @return void
133136
*/
137+
#[\ReturnTypeWillChange]
134138
public function offsetSet($offset, $value)
135139
{
136140
if ( ! isset($offset)) {
@@ -146,6 +150,7 @@ public function offsetSet($offset, $value)
146150
* @see set, offsetSet, __set
147151
* @param mixed $offset
148152
*/
153+
#[\ReturnTypeWillChange]
149154
public function offsetUnset($offset)
150155
{
151156
return $this->remove($offset);

lib/Doctrine/Adapter/Mock.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ public function lastInsertId()
238238
*
239239
* @return integer $count
240240
*/
241+
#[\ReturnTypeWillChange]
241242
public function count()
242243
{
243244
return count($this->_queries);

lib/Doctrine/Collection.php

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,38 @@ public function setData(array $data)
142142
$this->data = $data;
143143
}
144144

145+
145146
/**
146147
* This method is automatically called when this Doctrine_Collection is serialized
147148
*
148-
* @return array
149+
* @return string
149150
*/
150151
public function serialize()
151152
{
153+
$vars = $this->__serialize();
154+
155+
return serialize($vars);
156+
}
157+
158+
/**
159+
* This method is automatically called everytime a Doctrine_Collection object is unserialized
160+
*
161+
* @return void
162+
*/
163+
public function unserialize($serialized)
164+
{
165+
$array = unserialize($serialized);
166+
167+
$this->__unserialize($array);
168+
}
169+
170+
/**
171+
* Serializes the current instance for php 7.4+
172+
*
173+
* @return array
174+
*/
175+
public function __serialize() {
176+
152177
$vars = get_object_vars($this);
153178

154179
unset($vars['reference']);
@@ -160,22 +185,21 @@ public function serialize()
160185

161186
$vars['_table'] = $vars['_table']->getComponentName();
162187

163-
return serialize($vars);
188+
return $vars;
164189
}
165190

166191
/**
167-
* This method is automatically called everytime a Doctrine_Collection object is unserialized
192+
* Unserializes a Doctrine_Collection instance for php 7.4+
168193
*
169-
* @return void
194+
* @param string $serialized A serialized Doctrine_Collection instance
170195
*/
171-
public function unserialize($serialized)
196+
public function __unserialize($data)
172197
{
173198
$manager = Doctrine_Manager::getInstance();
174199
$connection = $manager->getCurrentConnection();
175200

176-
$array = unserialize($serialized);
177201

178-
foreach ($array as $name => $values) {
202+
foreach ($data as $name => $values) {
179203
$this->$name = $values;
180204
}
181205

@@ -432,6 +456,7 @@ public function getKeys()
432456
*
433457
* @return integer
434458
*/
459+
#[\ReturnTypeWillChange]
435460
public function count()
436461
{
437462
return count($this->data);
@@ -1036,6 +1061,7 @@ public function free($deep = false)
10361061
*
10371062
* @return Iterator
10381063
*/
1064+
#[\ReturnTypeWillChange]
10391065
public function getIterator()
10401066
{
10411067
$data = $this->data;

lib/Doctrine/Collection/OnDemand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ private function _hydrateCurrent()
6464
}
6565
}
6666

67+
#[\ReturnTypeWillChange]
6768
public function rewind()
6869
{
6970
$this->index = 0;
@@ -73,23 +74,27 @@ public function rewind()
7374
$this->_hydrateCurrent();
7475
}
7576

77+
#[\ReturnTypeWillChange]
7678
public function key()
7779
{
7880
return $this->index;
7981
}
8082

83+
#[\ReturnTypeWillChange]
8184
public function current()
8285
{
8386
return $this->_current;
8487
}
8588

89+
#[\ReturnTypeWillChange]
8690
public function next()
8791
{
8892
$this->_current = null;
8993
$this->index++;
9094
$this->_hydrateCurrent();
9195
}
9296

97+
#[\ReturnTypeWillChange]
9398
public function valid()
9499
{
95100
if ( ! is_null($this->_current) && $this->_current !== false) {

lib/Doctrine/Connection.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,7 @@ public function getTables()
11781178
*
11791179
* @return ArrayIterator SPL ArrayIterator object
11801180
*/
1181+
#[\ReturnTypeWillChange]
11811182
public function getIterator()
11821183
{
11831184
return new ArrayIterator($this->tables);
@@ -1188,6 +1189,7 @@ public function getIterator()
11881189
*
11891190
* @return integer
11901191
*/
1192+
#[\ReturnTypeWillChange]
11911193
public function count()
11921194
{
11931195
return $this->_count;
@@ -1606,16 +1608,16 @@ public function __toString()
16061608
return Doctrine_Lib::getConnectionAsString($this);
16071609
}
16081610

1611+
16091612
/**
16101613
* Serialize. Remove database connection(pdo) since it cannot be serialized
16111614
*
16121615
* @return string $serialized
16131616
*/
16141617
public function serialize()
16151618
{
1616-
$vars = get_object_vars($this);
1617-
$vars['dbh'] = null;
1618-
$vars['isConnected'] = false;
1619+
$vars = $this->__serialize();
1620+
16191621
return serialize($vars);
16201622
}
16211623

@@ -1629,7 +1631,32 @@ public function unserialize($serialized)
16291631
{
16301632
$array = unserialize($serialized);
16311633

1632-
foreach ($array as $name => $values) {
1634+
$this->__unserialize($array);
1635+
}
1636+
1637+
/**
1638+
* Serialize. Remove database connection(pdo) since it cannot be serialized for PHP 7.4+
1639+
*
1640+
* @return array
1641+
*/
1642+
public function __serialize()
1643+
{
1644+
$vars = get_object_vars($this);
1645+
$vars['dbh'] = null;
1646+
$vars['isConnected'] = false;
1647+
1648+
return $vars;
1649+
}
1650+
1651+
/**
1652+
* Unserialize. Recreate connection from serialized content PHP 7.4+
1653+
*
1654+
* @param array $data
1655+
* @return void
1656+
*/
1657+
public function __unserialize($data)
1658+
{
1659+
foreach ($data as $name => $values) {
16331660
$this->$name = $values;
16341661
}
16351662
}

lib/Doctrine/Connection/Mysql.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ public function __construct(Doctrine_Manager $manager, $adapter)
8585

8686
$this->properties['varchar_max_length'] = 255;
8787

88+
// PHP8.1 require default to true to keep BC
89+
// https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.mysql
90+
// Can be overwritten by user later
91+
$this->setAttribute(Doctrine_Core::ATTR_STRINGIFY_FETCHES, true);
92+
8893
parent::__construct($manager, $adapter);
8994
}
9095

lib/Doctrine/Connection/Profiler.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public function __construct() {
6868
* @return boolean
6969
*/
7070
public function setFilterQueryType() {
71-
72-
}
71+
72+
}
7373
/**
7474
* method overloader
7575
* this method is used for invoking different listeners, for the full
@@ -109,7 +109,7 @@ public function __call($m, $a)
109109
* @param mixed $key
110110
* @return Doctrine_Event
111111
*/
112-
public function get($key)
112+
public function get($key)
113113
{
114114
if (isset($this->events[$key])) {
115115
return $this->events[$key];
@@ -123,7 +123,7 @@ public function get($key)
123123
*
124124
* @return array all events in an array
125125
*/
126-
public function getAll()
126+
public function getAll()
127127
{
128128
return $this->events;
129129
}
@@ -134,17 +134,19 @@ public function getAll()
134134
*
135135
* @return ArrayIterator
136136
*/
137+
#[\ReturnTypeWillChange]
137138
public function getIterator()
138139
{
139140
return new ArrayIterator($this->events);
140141
}
141142

142143
/**
143144
* count
144-
*
145+
*
145146
* @return integer
146147
*/
147-
public function count()
148+
#[\ReturnTypeWillChange]
149+
public function count()
148150
{
149151
return count($this->events);
150152
}
@@ -154,7 +156,7 @@ public function count()
154156
*
155157
* @return Doctrine_Event
156158
*/
157-
public function pop()
159+
public function pop()
158160
{
159161
$event = array_pop($this->events);
160162
if ($event !== null)

lib/Doctrine/Connection/Sqlite.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,15 @@ public function __construct(Doctrine_Manager $manager, $adapter)
6565
'identifier_quoting' => true,
6666
'pattern_escaping' => false,
6767
);
68-
parent::__construct($manager, $adapter);
68+
parent::__construct($manager, $adapter);
6969

7070
if ($this->isConnected) {
71+
72+
// PHP8.1 require default to true to keep BC
73+
// https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.sqlite
74+
// Can be overwritten by user later
75+
$this->dbh->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
76+
7177
$this->dbh->sqliteCreateFunction('mod', array('Doctrine_Expression_Sqlite', 'modImpl'), 2);
7278
$this->dbh->sqliteCreateFunction('concat', array('Doctrine_Expression_Sqlite', 'concatImpl'));
7379
$this->dbh->sqliteCreateFunction('md5', 'md5', 1);
@@ -87,8 +93,18 @@ public function connect()
8793
return false;
8894
}
8995

96+
// If customer configure it
97+
$hasConfigureStringify = (isset($this->pendingAttributes[Doctrine_Core::ATTR_STRINGIFY_FETCHES]));
98+
9099
parent::connect();
91100

101+
if(!$hasConfigureStringify) {
102+
// PHP8.1 require default to true to keep BC
103+
// https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.sqlite
104+
// Can be overwritten by user later
105+
$this->dbh->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
106+
}
107+
92108
$this->dbh->sqliteCreateFunction('mod', array('Doctrine_Expression_Sqlite', 'modImpl'), 2);
93109
$this->dbh->sqliteCreateFunction('concat', array('Doctrine_Expression_Sqlite', 'concatImpl'));
94110
$this->dbh->sqliteCreateFunction('md5', 'md5', 1);

0 commit comments

Comments
 (0)