diff --git a/base.php b/base.php index a79fa2c1..3e8fd721 100644 --- a/base.php +++ b/base.php @@ -221,11 +221,11 @@ function parse($str) { * @return mixed */ function cast($val) { - if (preg_match('/^(?:0x[0-9a-f]+|0[0-7]+|0b[01]+)$/i',$val)) + if ($val && preg_match('/^(?:0x[0-9a-f]+|0[0-7]+|0b[01]+)$/i',$val)) return intval($val,0); if (is_numeric($val)) return $val+0; - $val=trim($val); + $val=trim($val?:''); if (preg_match('/^\w+$/i',$val) && defined($val)) return constant($val); return $val; @@ -829,7 +829,7 @@ function constants($class,$prefix='') { **/ function hash($str) { return str_pad(base_convert( - substr(sha1($str),-16),16,36),11,'0',STR_PAD_LEFT); + substr(sha1($str?:''),-16),16,36),11,'0',STR_PAD_LEFT); } /** @@ -968,6 +968,7 @@ function($expr) use($args,$conv) { isset($prop)?$prop:null ] ); + $php81=version_compare(PHP_VERSION, '8.1.0')>=0; switch ($type) { case 'plural': preg_match_all('/(?\w+)'. @@ -1051,19 +1052,42 @@ function_exists('money_format') && ($frac?strlen($frac)-2:0), $decimal_point,$thousands_sep); case 'date': - if (empty($mod) || $mod=='short') - $prop='%x'; - elseif ($mod=='full') - $prop='%A, %d %B %Y'; - elseif ($mod!='custom') - $prop='%d %B %Y'; - return strftime($prop,$args[$pos]); + if ($php81) { + $lang = $this->split($this->LANGUAGE); + // requires intl extension + $formatter = new IntlDateFormatter($lang[0], + (empty($mod) || $mod=='short') + ? IntlDateFormatter::SHORT : + ($mod=='full' ? IntlDateFormatter::LONG : IntlDateFormatter::MEDIUM), + IntlDateFormatter::NONE); + return $formatter->format($args[$pos]); + } else { + if (empty($mod) || $mod=='short') + $prop='%x'; + elseif ($mod=='full') + $prop='%A, %d %B %Y'; + elseif ($mod!='custom') + $prop='%d %B %Y'; + return strftime($prop,$args[$pos]); + } case 'time': - if (empty($mod) || $mod=='short') - $prop='%X'; - elseif ($mod!='custom') - $prop='%r'; - return strftime($prop,$args[$pos]); + if ($php81) { + $lang = $this->split($this->LANGUAGE); + // requires intl extension + $formatter = new IntlDateFormatter($lang[0], + IntlDateFormatter::NONE, + (empty($mod) || $mod=='short') + ? IntlDateFormatter::SHORT : + ($mod=='full' ? IntlDateFormatter::LONG : IntlDateFormatter::MEDIUM), + IntlTimeZone::createTimeZone($this->hive['TZ'])); + return $formatter->format($args[$pos]); + } else { + if (empty($mod) || $mod=='short') + $prop='%X'; + elseif ($mod!='custom') + $prop='%r'; + return strftime($prop,$args[$pos]); + } default: return $expr[0]; } @@ -1424,7 +1448,7 @@ function mock($pattern, if (empty($parts[4])) user_error(sprintf(self::E_Pattern,$pattern),E_USER_ERROR); $url=parse_url($parts[4]); - parse_str(@$url['query'],$GLOBALS['_GET']); + parse_str(isset($url['query'])?$url['query']:'',$GLOBALS['_GET']); if (preg_match('/GET|HEAD/',$verb)) $GLOBALS['_GET']=array_merge($GLOBALS['_GET'],$args); $GLOBALS['_POST']=$verb=='POST'?$args:[]; @@ -1775,7 +1799,7 @@ function($id) use($args) { ++$ctr; if ($ctr/$kbps>($elapsed=microtime(TRUE)-$now) && !connection_aborted()) - usleep(1e6*($ctr/$kbps-$elapsed)); + usleep(round(1e6*($ctr/$kbps-$elapsed))); echo $part; } } @@ -2382,7 +2406,7 @@ function($level,$text,$file,$line) { $req.='?'.$query; } $_SERVER['REQUEST_URI']=$req; - parse_str($query,$GLOBALS['_GET']); + parse_str($query?:'',$GLOBALS['_GET']); } elseif (function_exists('getallheaders')) { foreach (getallheaders() as $key=>$val) { @@ -2705,7 +2729,7 @@ function reset($suffix=NULL) { if (!$this->dsn) return TRUE; $regex='/'.preg_quote($this->prefix.'.','/').'.*'. - preg_quote($suffix,'/').'/'; + preg_quote($suffix?:'','/').'/'; $parts=explode('=',$this->dsn,2); switch ($parts[0]) { case 'apc': diff --git a/basket.php b/basket.php index 70caceed..924b84ec 100644 --- a/basket.php +++ b/basket.php @@ -148,7 +148,7 @@ function count() { **/ function save() { if (!$this->id) - $this->id=uniqid(NULL,TRUE); + $this->id=uniqid('',TRUE); $_SESSION[$this->key][$this->id]=$this->item; return $this->item; } diff --git a/db/cursor.php b/db/cursor.php index 2fd324a0..266a143b 100644 --- a/db/cursor.php +++ b/db/cursor.php @@ -107,6 +107,7 @@ abstract function copyto($key); * Causes a fatal error in PHP 5.3.5 if uncommented * return ArrayIterator **/ + #[\ReturnTypeWillChange] abstract function getiterator(); diff --git a/db/jig/mapper.php b/db/jig/mapper.php index 5d26427f..b6fbfa85 100644 --- a/db/jig/mapper.php +++ b/db/jig/mapper.php @@ -383,7 +383,7 @@ function insert() { return $this->update(); $db=$this->db; $now=microtime(TRUE); - while (($id=uniqid(NULL,TRUE)) && + while (($id=uniqid('',TRUE)) && ($data=&$db->read($this->file)) && isset($data[$id]) && !connection_aborted()) usleep(mt_rand(0,100)); diff --git a/db/mongo/mapper.php b/db/mongo/mapper.php index 0246f6d7..71de62c7 100644 --- a/db/mongo/mapper.php +++ b/db/mongo/mapper.php @@ -150,7 +150,7 @@ function select($fields=NULL,$filter=NULL,array $options=NULL,$ttl=0) { ); $tmp=$this->db->selectcollection( $fw->HOST.'.'.$fw->BASE.'.'. - uniqid(NULL,TRUE).'.tmp' + uniqid('',TRUE).'.tmp' ); $tmp->batchinsert($grp['retval'],['w'=>1]); $filter=[]; diff --git a/image.php b/image.php index b7f149ce..367ca6e3 100644 --- a/image.php +++ b/image.php @@ -258,12 +258,12 @@ function resize($width=NULL,$height=NULL,$crop=TRUE,$enlarge=TRUE) { if ($width/$ratio<=$height) { $cropw=round($origh*$width/$height); imagecopyresampled($tmp,$this->data, - 0,0,($origw-$cropw)/2,0,$width,$height,$cropw,$origh); + 0,0,round(($origw-$cropw)/2),0,$width,$height,$cropw,$origh); } else { $croph=round($origw*$height/$width); imagecopyresampled($tmp,$this->data, - 0,0,0,($origh-$croph)/2,$width,$height,$origw,$croph); + 0,0,0,round(($origh-$croph)/2),$width,$height,$origw,$croph); } } else @@ -309,13 +309,13 @@ function overlay(Image $img,$align=NULL,$alpha=100) { if ($align & self::POS_Left) $posx=0; if ($align & self::POS_Center) - $posx=($imgw-$ovrw)/2; + $posx=round(($imgw-$ovrw)/2); if ($align & self::POS_Right) $posx=$imgw-$ovrw; if ($align & self::POS_Top) $posy=0; if ($align & self::POS_Middle) - $posy=($imgh-$ovrh)/2; + $posy=round(($imgh-$ovrh)/2); if ($align & self::POS_Bottom) $posy=$imgh-$ovrh; if (empty($posx)) @@ -374,10 +374,14 @@ function identicon($str,$size=64,$blocks=4) { $block=$sprites[hexdec($hash[($j*$blocks+$i)*2])%$ctr]; for ($k=0,$pts=count($block);$k<$pts;++$k) $block[$k]*=$dim; - imagefilledpolygon($sprite,$block,$pts/2,$fg); + if (version_compare(PHP_VERSION, '8.1.0') >= 0) { + imagefilledpolygon($sprite,$block,$fg); + } else { + imagefilledpolygon($sprite,$block,$pts/2,$fg); + } for ($k=0;$k<4;++$k) { imagecopyresampled($this->data,$sprite, - $i*$dim/2,$j*$dim/2,0,0,$dim/2,$dim/2,$dim,$dim); + round($i*$dim/2),round($j*$dim/2),0,0,round($dim/2),round($dim/2),$dim,$dim); $this->data=imagerotate($this->data,90, imagecolorallocatealpha($this->data,0,0,0,127)); } @@ -424,25 +428,25 @@ function captcha($font,$size=24,$len=5, $char=imagecreatetruecolor($block,$block); imagefill($char,0,0,$bg); imagettftext($char,$size*2,0, - ($block-$w)/2,$block-($block-$h)/2, + round(($block-$w)/2),round($block-($block-$h)/2), $fg,$path,$seed[$i]); $char=imagerotate($char,mt_rand(-30,30), imagecolorallocatealpha($char,0,0,0,127)); // Reduce to normal size $tmp[$i]=imagecreatetruecolor( - ($w=imagesx($char))/2,($h=imagesy($char))/2); + round(($w=imagesx($char))/2),round(($h=imagesy($char))/2)); imagefill($tmp[$i],0,0,IMG_COLOR_TRANSPARENT); imagecopyresampled($tmp[$i], - $char,0,0,0,0,$w/2,$h/2,$w,$h); + $char,0,0,0,0,round($w/2),round($h/2),$w,$h); imagedestroy($char); $width+=$i+1<$len?$block/2:$w/2; $height=max($height,$h/2); } - $this->data=imagecreatetruecolor($width,$height); + $this->data=imagecreatetruecolor(round($width),round($height)); imagefill($this->data,0,0,IMG_COLOR_TRANSPARENT); for ($i=0;$i<$len;++$i) { imagecopy($this->data,$tmp[$i], - $i*$block/2,($height-imagesy($tmp[$i]))/2,0,0, + round($i*$block/2),round(($height-imagesy($tmp[$i]))/2),0,0, imagesx($tmp[$i]),imagesy($tmp[$i])); imagedestroy($tmp[$i]); } diff --git a/magic.php b/magic.php index f676506f..92398a5f 100644 --- a/magic.php +++ b/magic.php @@ -57,6 +57,7 @@ abstract function clear($key); * @return mixed * @param $key string **/ + #[\ReturnTypeWillChange] function offsetexists($key) { return Base::instance()->visible($this,$key)? isset($this->$key): @@ -69,6 +70,7 @@ function offsetexists($key) { * @param $key string * @param $val mixed **/ + #[\ReturnTypeWillChange] function offsetset($key,$val) { return Base::instance()->visible($this,$key)? ($this->$key=$val):$this->set($key,$val); @@ -79,6 +81,7 @@ function offsetset($key,$val) { * @return mixed * @param $key string **/ + #[\ReturnTypeWillChange] function &offsetget($key) { if (Base::instance()->visible($this,$key)) $val=&$this->$key; @@ -92,6 +95,7 @@ function &offsetget($key) { * @return NULL * @param $key string **/ + #[\ReturnTypeWillChange] function offsetunset($key) { if (Base::instance()->visible($this,$key)) unset($this->$key); diff --git a/smtp.php b/smtp.php index 0f66ca54..077de87d 100644 --- a/smtp.php +++ b/smtp.php @@ -283,7 +283,7 @@ function send($message,$log=TRUE,$mock=FALSE) { unset($headers['Content-Type']); $enc=$headers['Content-Transfer-Encoding']; unset($headers['Content-Transfer-Encoding']); - $hash=uniqid(NULL,TRUE); + $hash=uniqid('',TRUE); // Send mail headers $out='Content-Type: multipart/mixed; boundary="'.$hash.'"'.$eol; foreach ($headers as $key=>$val) diff --git a/template.php b/template.php index fb6f21dd..57062ea3 100644 --- a/template.php +++ b/template.php @@ -43,7 +43,7 @@ protected function _set(array $node) { $out=''; foreach ($node['@attrib'] as $key=>$val) $out.='$'.$key.'='. - (preg_match('/\{\{(.+?)\}\}/',$val)? + (preg_match('/\{\{(.+?)\}\}/',$val?:'')? $this->token($val): Base::instance()->stringify($val)).'; '; return ''; diff --git a/web.php b/web.php index 7a69051d..4019ff4f 100644 --- a/web.php +++ b/web.php @@ -232,7 +232,7 @@ function send($file,$mime=NULL,$kbps=0,$force=TRUE,$name=NULL,$flush=TRUE) { // Throttle output ++$ctr; if ($ctr/$kbps>$elapsed=microtime(TRUE)-$start) - usleep(1e6*($ctr/$kbps-$elapsed)); + usleep(round(1e6*($ctr/$kbps-$elapsed))); } // Send 1KiB and reset timer echo fread($handle,1024); @@ -1006,7 +1006,7 @@ function gzdecode($str) { if (!is_dir($tmp=$fw->TEMP)) mkdir($tmp,Base::MODE,TRUE); file_put_contents($file=$tmp.'/'.$fw->SEED.'.'. - $fw->hash(uniqid(NULL,TRUE)).'.gz',$str,LOCK_EX); + $fw->hash(uniqid('',TRUE)).'.gz',$str,LOCK_EX); ob_start(); readgzfile($file); $out=ob_get_clean();