From 2b13737e9299317c865f72f4a276ea0b733c4f5f Mon Sep 17 00:00:00 2001
From: Christian Schneider
Date: Mon, 2 Sep 2019 17:14:43 +0200
Subject: Make itools a bit stricter, new PHP versions start to enforce more
declarations
---
it.class | 4 ++--
it_html.class | 4 ++--
it_mail.class | 4 ++--
it_text.class | 4 ++--
it_url.class | 6 +++---
itjs.class | 2 +-
test/it.t | 3 ++-
test/it_html.t | 4 ++--
test/it_xml.t | 2 +-
9 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/it.class b/it.class
index 87a8b07..976afe9 100644
--- a/it.class
+++ b/it.class
@@ -372,7 +372,7 @@ static function toascii($text)
* @param $cidrs IP range in CIDR notation (192.168.42.64/26) or array of ranges
* @return true if $ip is within $cidr
*/
-function cidr_match($ip, $cidrs)
+static function cidr_match($ip, $cidrs)
{
foreach ((array)$cidrs as $cidr)
{
@@ -381,7 +381,7 @@ function cidr_match($ip, $cidrs)
$subnet_bin = inet_pton($subnet);
$valid_bytes = $mask ? $mask >> 3 : 42;
$bitmask = 256 - (1 << (8 - ($mask & 7)));
- $lastbyte_matched = $bitmask ? (ord($ip_bin{$valid_bytes}) & $bitmask) == (ord($subnet_bin{$valid_bytes}) & $bitmask) : true;
+ $lastbyte_matched = $bitmask ? (ord($ip_bin[$valid_bytes]) & $bitmask) == (ord($subnet_bin[$valid_bytes]) & $bitmask) : true;
if (substr($ip_bin, 0, $valid_bytes) == substr($subnet_bin, 0, $valid_bytes) && $lastbyte_matched)
return true;
diff --git a/it_html.class b/it_html.class
index 390e8ae..04d6f2b 100644
--- a/it_html.class
+++ b/it_html.class
@@ -392,7 +392,7 @@ function select($tags, $options, $selected = null)
/**
* Outputs string as correctly quoted HTML comment
*/
-function comment($string)
+static function comment($string)
{
return "";
}
@@ -453,7 +453,7 @@ static function sanitize($html)
/**
* Decode all entities to encoding set for it_html
*/
-function entity_decode($string)
+static function entity_decode($string)
{
$charset = $GLOBALS['it_html']->p['charset'];
$string = preg_replace('/(8217|65533);/', "'", html_entity_decode($string, ENT_COMPAT, $charset));
diff --git a/it_mail.class b/it_mail.class
index 8cb73fe..4033c06 100644
--- a/it_mail.class
+++ b/it_mail.class
@@ -308,9 +308,9 @@ function header_escape($string)
? ltrim(
($encoded = @iconv_mime_encode('', $string, array('scheme' => 'Q', 'input-charset' => $this->charset, 'output-charset' => $this->charset))) !== false
? $encoded
- : ($encoded = @iconv_mime_encode('', $string, array('scheme' => 'B', 'input-charset' => $this->charset, 'output-charset' => $this->charset))) !== false
+ : (($encoded = @iconv_mime_encode('', $string, array('scheme' => 'B', 'input-charset' => $this->charset, 'output-charset' => $this->charset))) !== false
? $encoded
- : iconv_mime_encode('', $string, array('scheme', 'B', 'input-charset' => 'ISO-8859-1', 'output-charset' => $this->charset)),
+ : iconv_mime_encode('', $string, array('scheme', 'B', 'input-charset' => 'ISO-8859-1', 'output-charset' => $this->charset))),
' :'
)
: $string;
diff --git a/it_text.class b/it_text.class
index 443b34b..660213e 100644
--- a/it_text.class
+++ b/it_text.class
@@ -172,7 +172,7 @@ function text($label, $language = null)
*/
function etext($label, $values = null, $language = null)
{
- return $this->transmogrify($this->text($label, $language), $values, $label, $this->allowedfuncs);
+ return self::transmogrify($this->text($label, $language), $values, $label, $this->allowedfuncs);
}
@@ -231,7 +231,7 @@ function set($label, $text = null, $language = null)
* Replaces variables of the form {obj.var} with value from $values, e.g. {user.name}, or result of a func, e.g. {LU(//www/terms)}
* NOTE: Invalid object names or non-existing variables are simply deleted.
*/
-function transmogrify($text, $values = null, $label = null, $allowedfuncs = null)
+static function transmogrify($text, $values = null, $label = null, $allowedfuncs = null)
{
foreach (preg_split('#{([^}]*)}#', $text, -1, PREG_SPLIT_DELIM_CAPTURE) as $i => $part)
{
diff --git a/it_url.class b/it_url.class
index 12ac64a..80b7a44 100644
--- a/it_url.class
+++ b/it_url.class
@@ -59,7 +59,7 @@ function __construct($url = null)
$this->hostname = preg_replace('/^www\./', '', $this->realhostname);
$this->path = ltrim($comp['path'] . ($comp['query'] ? '?' . $comp['query'] : ''), '/'); # $this->path is named poorly, it includes path and query
$this->url = "$this->protocol://$this->realhostname" . ($this->port != $protoport ? $this->explicitport : '') . "/$this->path";
- $this->realhostname = idn_to_ascii($this->realhostname) ?: $this->realhostname; # punycode or original
+ $this->realhostname = idn_to_ascii($this->realhostname, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46) ?: $this->realhostname; # punycode or original
}
@@ -316,7 +316,7 @@ function request($p=array())
* @return array of contents (or false for errors like timesou) of resulting page using same
* keys as the urls input array, considering redirects, excluding headers
*/
-function get_multi($p=null)
+static function get_multi($p=null)
{
$p += array('retries' => 1);
@@ -453,7 +453,7 @@ static function get_cache_filename($p)
* @param $p['returnheaders'] Return array($path, $headers) instead of simply $path
* @return Cache filename or false if fetch failed
*/
-function get_cache($p = array())
+static function get_cache($p = array())
{
if (!$p['id'] && $p['maxage'])
it::error("calling get_cache with maxage and without id");
diff --git a/itjs.class b/itjs.class
index 2e7cf48..c7db13a 100644
--- a/itjs.class
+++ b/itjs.class
@@ -195,7 +195,7 @@ static function checksum($fnlist, $p = array())
/**
* Convert url or TRUSTED local path to url that triggers far future expire by appending c=checksum
*/
-function crcurl($url, $p = array())
+static function crcurl($url, $p = array())
{
if (it::match('^(http|//)', $url)) # remote url, must fetch to crc
list($fn, $short_expire) = array(it_url::get_cache(array('url' => $url, 'maxage' => 3600, 'id' => "itjs_crcurl") + $p), false);
diff --git a/test/it.t b/test/it.t
index b624f96..0e2b06d 100755
--- a/test/it.t
+++ b/test/it.t
@@ -445,7 +445,8 @@ is(it::map('5*$k+$v', array(0 => 1, 1 => 2)), array(1, 7));
is(it::map(function($k, $v) {return 5*$k+$v;}, array(0 => 1, 1 => 2)), array(1, 7));
is(it::map('strlen', array("aaa", "aa")), array(3, 2));
is(it::map('it::ucfirst', array("aaa")), array("Aaa"));
-is(it::map('$v->C14N()', DOMDocument::loadXML('42')->childNodes), [ '42' ], "Traversable: Needs copy, not modifiable in-place");
+($dom = new DOMDocument)->loadXML('42');
+is(it::map('$v->C14N()', $dom->childNodes), [ '42' ], "Traversable: Needs copy, not modifiable in-place");
# Special values which are not callable
is(it::map('null', array("aaa", "aa")), array(null, null));
is(it::map('1', array("aaa", "aa")), array(1, 1));
diff --git a/test/it_html.t b/test/it_html.t
index 5e19b74..f5daebd 100755
--- a/test/it_html.t
+++ b/test/it_html.t
@@ -175,7 +175,7 @@ is(
class myhtml extends it_html
{
-function myhtml($p = array())
+function __construct($p = array())
{
parent::__construct($p + ['moretags' => 'overriddentag,defaulttag', 'nonewlinetags' => 'a,b,defaulttag,em,img,input,overriddentag,span,div']);
}
@@ -253,7 +253,7 @@ is(
'empty tags removal'
);
-foreach (json_decode(file_get_contents(dirname($argv[0]) . '/U_tests.json'), true) as $test) {
+foreach (json_decode(it::file_get_contents(dirname($argv[0]) . '/U_tests.json'), true) as $test) {
is(U(...$test['args']), $test['exp'], $test['name']);
}
diff --git a/test/it_xml.t b/test/it_xml.t
index 4df340a..84f258f 100755
--- a/test/it_xml.t
+++ b/test/it_xml.t
@@ -95,7 +95,7 @@ match(
class my_xml extends it_xml
{
-function my_xml($xmldata)
+function __construct($xmldata)
{
parent::__construct($xmldata);
--
cgit v1.2.3