Skip to content

Commit

Permalink
Experimental forward compatibility with PHP 9.0
Browse files Browse the repository at this point in the history
This is basically 3.1.0 "beta" now
  • Loading branch information
darkain committed Jun 10, 2022
1 parent 547af2e commit 4acd807
Show file tree
Hide file tree
Showing 26 changed files with 534 additions and 117 deletions.
4 changes: 2 additions & 2 deletions mssql/pudlMsSqlResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function cell($row=0, $column=0) {
// http://php.net/manual/en/countable.count.php
// http://php.net/manual/en/function.mssql-num-rows.php
////////////////////////////////////////////////////////////////////////////
public function count() {
public function _count() {
$rows = false;
if ($this->result) $rows = @mssql_num_rows($this->result);
return ($rows !== false) ? $rows : 0;
Expand Down Expand Up @@ -90,7 +90,7 @@ public function getField($column) {
// http://php.net/manual/en/seekableiterator.seek.php
// http://php.net/manual/en/function.mssql-data-seek.php
////////////////////////////////////////////////////////////////////////////
public function seek($row) {
public function _seek($row) {
if ($this->result) @mssql_data_seek($this->result, $row);
}

Expand Down
4 changes: 2 additions & 2 deletions mssql/pudlSqlSrvResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function cell($row=0, $column=0) {
// http://php.net/manual/en/countable.count.php
// http://php.net/manual/en/function.sqlsrv-num-rows.php
////////////////////////////////////////////////////////////////////////////
public function count() {
public function _count() {
if (!$this->result) return 0;
$rows = @sqlsrv_num_rows($this->result);
return (!empty($rows)) ? $rows : 0;
Expand Down Expand Up @@ -90,7 +90,7 @@ public function getField($column) {
// http://php.net/manual/en/seekableiterator.seek.php
// http://php.net/manual/en/function.sqlsrv-fetch.php
////////////////////////////////////////////////////////////////////////////
public function seek($row) {
public function _seek($row) {
if (!$this->result) return;
@sqlsrv_fetch($this->result, SQLSRV_SCROLL_ABSOLUTE, $row);
}
Expand Down
4 changes: 2 additions & 2 deletions mysql/pudlMySqlResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function cell($row=0, $column=0) {
// http://php.net/manual/en/countable.count.php
// http://php.net/manual/en/function.mysql-num-rows.php
////////////////////////////////////////////////////////////////////////////
public function count() {
public function _count() {
$rows = false;
if ($this->result) $rows = @mysql_num_rows($this->result);
return ($rows !== false) ? $rows : 0;
Expand Down Expand Up @@ -90,7 +90,7 @@ public function getField($column) {
// http://php.net/manual/en/seekableiterator.seek.php
// http://php.net/manual/en/function.mysql-data-seek.php
////////////////////////////////////////////////////////////////////////////
public function seek($row) {
public function _seek($row) {
if ($this->result) @mysql_data_seek($this->result, $row);
}

Expand Down
4 changes: 2 additions & 2 deletions mysql/pudlMySqliResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function cell($row=0, $column=0) {
// http://php.net/manual/en/countable.count.php
// http://php.net/manual/en/mysqli-result.num-rows.php
////////////////////////////////////////////////////////////////////////////
public function count() {
public function _count() {
$rows = false;
if ($this->result instanceof mysqli_result) {
$rows = $this->result->num_rows;
Expand Down Expand Up @@ -117,7 +117,7 @@ public function getField($column) {
// http://php.net/manual/en/seekableiterator.seek.php
// http://php.net/manual/en/mysqli-result.data-seek.php
////////////////////////////////////////////////////////////////////////////
public function seek($row) {
public function _seek($row) {
if ($this->result instanceof mysqli_result) {
@$this->result->data_seek($row);
}
Expand Down
4 changes: 2 additions & 2 deletions null/pudlNullResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class pudlNullResult extends pudlResult {
////////////////////////////////////////////////////////////////////////////
public function free() {}
public function cell($row=0, $column=0) { return false; }
public function count() { return 0; }
public function _count() { return 0; }
public function fields() { return false; }
public function getField($column) { return false; }
public function seek($row) {}
public function _seek($row) {}
public function row() { return false; }
public function errno() { return 0; }
public function error() { return ''; }
Expand Down
4 changes: 2 additions & 2 deletions odbc/pudlOdbcResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function cell($row=0, $column=0) {
// http://php.net/manual/en/countable.count.php
// http://php.net/manual/en/function.odbc-num-rows.php
////////////////////////////////////////////////////////////////////////////
public function count() {
public function _count() {
$rows = false;
if ($this->result) $rows = @odbc_num_rows($this->result);
return ($rows !== false && $rows > 0) ? $rows : 0;
Expand Down Expand Up @@ -91,7 +91,7 @@ public function getField($column) {
// PHP'S SEEKABLEITERATOR - JUMP TO A ROW IN THIS RESULT
// http://php.net/manual/en/seekableiterator.seek.php
////////////////////////////////////////////////////////////////////////////
public function seek($row) {
public function _seek($row) {
if ($this->result) $this->row = (int) $row;
}

Expand Down
4 changes: 2 additions & 2 deletions pdo/pudlPdoResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function cell($row=0, $column=0) {
// http://php.net/manual/en/countable.count.php
// http://php.net/manual/en/pdostatement.rowcount.php
////////////////////////////////////////////////////////////////////////////
public function count() {
public function _count() {
if (!is_object($this->result)) return 0;
return $this->result->rowCount();
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public function getField($column) {
// http://php.net/manual/en/seekableiterator.seek.php
// http://php.net/manual/en/pdostatement.fetch.php
////////////////////////////////////////////////////////////////////////////
public function seek($row) {
public function _seek($row) {
if (!is_object($this->result)) return;
$this->result->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_ABS, $row);
if (!$row) $this->seekzero = true;
Expand Down
4 changes: 2 additions & 2 deletions pgsql/pudlPgSqlResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function cell($row=0, $column=0) {
// http://php.net/manual/en/countable.count.php
// http://php.net/manual/en/function.pg-num-rows.php
////////////////////////////////////////////////////////////////////////////
public function count() {
public function _count() {
$rows = false;
if ($this->result) $rows = @pg_num_rows($this->result);
return ($rows !== false && $rows > 0) ? $rows : 0;
Expand Down Expand Up @@ -113,7 +113,7 @@ public function getField($column) {
// http://php.net/manual/en/seekableiterator.seek.php
// http://php.net/manual/en/function.pg-result-seek.php
////////////////////////////////////////////////////////////////////////////
public function seek($row) {
public function _seek($row) {
if ($this->result) @pg_result_seek($this->result, $row);
}

Expand Down
27 changes: 27 additions & 0 deletions pudlCollection.legacy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

trait pudlCollection_trait {



////////////////////////////////////////////////////////////////////////////
// RESET INTERNAL POINTER TO FIRST OBJECT IN COLLECTION
// https://www.php.net/manual/en/iterator.rewind.php
////////////////////////////////////////////////////////////////////////////
public function rewind() {
$this->_rewind();
}




////////////////////////////////////////////////////////////////////////////
// RETURNS THE INNER ITERATOR FOR THE CURRENT ENTRY.
// http://php.net/manual/en/outeriterator.getinneriterator.php
////////////////////////////////////////////////////////////////////////////
public function getInnerIterator() {
return $this->_getInnerIterator();
}


}
37 changes: 37 additions & 0 deletions pudlCollection.modern.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

trait pudlCollection_trait {



////////////////////////////////////////////////////////////////////////////
// RESET INTERNAL POINTER TO FIRST OBJECT IN COLLECTION
// https://www.php.net/manual/en/iterator.rewind.php
////////////////////////////////////////////////////////////////////////////
public function rewind() : void {
$this->_rewind();
}




////////////////////////////////////////////////////////////////////////////
// MOVE INTERNAL POINTER TO SPECIFIC ITEM WITHIN COLLECTION
////////////////////////////////////////////////////////////////////////////
public function seek($row) : void {
$this->_seek($row);
}




////////////////////////////////////////////////////////////////////////////
// RETURNS THE INNER ITERATOR FOR THE CURRENT ENTRY.
// http://php.net/manual/en/outeriterator.getinneriterator.php
////////////////////////////////////////////////////////////////////////////
public function getInnerIterator() : ?Iterator {
return $this->_getInnerIterator();
}


}
29 changes: 20 additions & 9 deletions pudlCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,23 @@




////////////////////////////////////////////////////////////////////////////////
// HANDLE PHP VERSION SPECIFIC IMPLEMENTATIONS
////////////////////////////////////////////////////////////////////////////////
if (version_compare(PHP_VERSION, '8.0.0') >= 0) {
require_once(is_owner(__DIR__.'/pudlCollection.modern.php'));
} else {
require_once(is_owner(__DIR__.'/pudlCollection.legacy.php'));
}




class pudlCollection
extends pudlObject
implements OuterIterator {

use pudlCollection_trait;



Expand Down Expand Up @@ -57,11 +70,11 @@ public function __invoke() {

////////////////////////////////////////////////////////////////////////////
// RESET INTERNAL POINTER TO FIRST OBJECT IN COLLECTION
// https://www.php.net/manual/en/iterator.rewind.php
////////////////////////////////////////////////////////////////////////////
#[\ReturnTypeWillChange]
public function rewind() {
public function _rewind() {
$this->first = true;
return pudlObject::rewind();
return pudlObject::_rewind();
}


Expand All @@ -70,10 +83,9 @@ public function rewind() {
////////////////////////////////////////////////////////////////////////////
// MOVE INTERNAL POINTER TO SPECIFIC ITEM WITHIN COLLECTION
////////////////////////////////////////////////////////////////////////////
#[\ReturnTypeWillChange]
public function seek($row) {
public function _seek($row) {
if (!$row) $this->first = true;
pudlObject::seek($row);
pudlObject::_seek($row);
}


Expand Down Expand Up @@ -180,8 +192,7 @@ public function column($column) {
// RETURNS THE INNER ITERATOR FOR THE CURRENT ENTRY.
// http://php.net/manual/en/outeriterator.getinneriterator.php
////////////////////////////////////////////////////////////////////////////
#[\ReturnTypeWillChange]
public function getInnerIterator() {
public function _getInnerIterator() {
return $this->current();
}

Expand Down
72 changes: 72 additions & 0 deletions pudlData.legacy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php




////////////////////////////////////////////////////////////////////////////////
// COMPATIBILITY SHIM FOR LEGACY AND MODERN PHP
////////////////////////////////////////////////////////////////////////////////
trait pudlData_shim {




////////////////////////////////////////////////////////////////////////////
// PULLED FROM PHPS BUILT IN COUNTABLE INTERFACE
////////////////////////////////////////////////////////////////////////////
public function count() {
return $this->_count();
}




////////////////////////////////////////////////////////////////////////////
// PULLED FROM PHPS BUILT IN SEEKABLEITERATOR INTERFACE
////////////////////////////////////////////////////////////////////////////
public function seek($position) {
$this->_seek($position);
}




////////////////////////////////////////////////////////////////////////////
// PULLED FROM PHPS BUILT IN ITERATOR INTERFACE
////////////////////////////////////////////////////////////////////////////
public function current() {
return $this->_current();
}


public function key() {
return $this->_key();
}


public function next() {
$this->_next();
}


public function rewind() {
$this->_rewind();
}


public function valid() {
return $this->_valid();
}




////////////////////////////////////////////////////////////////////////////
// PULLED FROM PHP'S BUILT IN JSONSERIALIZABLE INTERFACE
////////////////////////////////////////////////////////////////////////////
public function jsonSerialize() {
return $this->_jsonSerialize();
}


}
Loading

0 comments on commit 4acd807

Please sign in to comment.