Commit:    48cb59d3268189d10951d0e69465dfbb7a4cf852
Author:    Rasmus Lerdorf <[email protected]>         Sat, 30 Jan 2021 
13:18:46 -0800
Parents:   c84cdc756ae1671b373bfaea7ac242d621bb5f1b
Branches:  master

Link:       
http://git.php.net/?p=web/master.git;a=commitdiff;h=48cb59d3268189d10951d0e69465dfbb7a4cf852

Log:
A bit of PHP 7.4/8.0 cleanup

Changed paths:
  M  .phan/config.php
  M  entry/user-note.php
  M  fetch/events.php
  M  fetch/user.php
  M  include/alert_lib.inc
  M  include/functions.inc
  M  include/spam-lib.inc
  M  manage/event.php
  M  manage/github.php
  M  manage/user-notes.php
  M  manage/users.php
  M  vendor/michelf/php-markdown-extra/markdown.php

diff --git a/.phan/config.php b/.phan/config.php
index 7dcc368..d9e10bd 100644
--- a/.phan/config.php
+++ b/.phan/config.php
@@ -26,10 +26,10 @@ return [
     // Thus, both first-party and third-party code being used by
     // your application should be included in this list.
     'directory_list' => [
-        '.', 'manage', 'include',
+        'include', 'manage', '.',
     ],
 
-       'analyzed_file_extensions' => ['php', 'inc'],
+       'analyzed_file_extensions' => ['php', 'inc', 'sample'],
 
     // A regex used to match every file name that you want to
     // exclude from parsing. Actual value will exclude every
diff --git a/entry/user-note.php b/entry/user-note.php
index 776a03c..385df2b 100644
--- a/entry/user-note.php
+++ b/entry/user-note.php
@@ -145,6 +145,8 @@ if (@mysql_query($query)) {
       . str_pad($reason, $note_del_reasons_pad)
       . "-- https://master.php.net/note/delete/$new_id/"; . urlencode($reason) 
."\n";
   }
+
+  // @phan-suppress-next-line PhanParamSuspiciousOrder - weird global padding 
count, but ok
   $msg .= str_pad('Del: other reasons', $note_del_reasons_pad) . "-- 
https://master.php.net/note/delete/$new_id\n";;
   $msg .= "Reject      -- https://master.php.net/note/reject/$new_id\n";;
   $msg .= "Search      -- https://master.php.net/manage/user-notes.php\n";;
diff --git a/fetch/events.php b/fetch/events.php
index 9c32a91..33d2013 100644
--- a/fetch/events.php
+++ b/fetch/events.php
@@ -50,7 +50,7 @@ while ($nm) {
     }
 }
 
-/*
+/**
  * Find the first, second, third, last, second-last etc. weekday of a month
  *
  * args: day   1 = Monday
@@ -61,6 +61,11 @@ while ($nm) {
  *            -1 = last
  *            -2 = second-last
  *            -3 = third-last
+ *
+ * @param int $year
+ * @param int $month
+ * @param int $day
+ * @param int $which
  */
 function weekday($year, $month, $day, $which)
 {
@@ -132,7 +137,7 @@ function load_month($year, $month, $cat)
             // Recurring event
             case 3:
                 list($which,$dd) = explode(':', $row['recur']);
-                $ts = weekday($year, $month, $dd, $which);
+                $ts = weekday((int)$year, (int)$month, (int)$dd, (int)$which);
                 $events[(int)strftime('%d', $ts)][] = $row;
                 break;
         }
diff --git a/fetch/user.php b/fetch/user.php
index d312e2b..68ffbe9 100644
--- a/fetch/user.php
+++ b/fetch/user.php
@@ -41,6 +41,7 @@ if (!$stmt->execute([$results["userid"]])) {
 }
 
 unset($results["userid"]); // Our internal ID has no meaning for anyone
+// @phan-suppress-next-line PhanTypeArraySuspicious
 $results["notes"] = $stmt->fetchAll(PDO::FETCH_ASSOC);
 
 echo json_encode($results);
diff --git a/include/alert_lib.inc b/include/alert_lib.inc
index 3010cca..32564f7 100644
--- a/include/alert_lib.inc
+++ b/include/alert_lib.inc
@@ -33,7 +33,7 @@ function has_alert($user, $sect) {
 function do_alert_action($sql) {
        global $alink;
        $r = @mysql_query($sql, $alink);
-       $success = ($r && mysql_affected_rows($c) > 0);
+       $success = ($r && mysql_affected_rows($r) > 0);
        if (!$success)
                echo "<b>Error performing sql: ".mysql_error()." ( in 
do_alert_action() )";
        return $success;
@@ -67,6 +67,7 @@ function get_emails_for_sect($sect) {
        $sql = "select cvsusers.email from alerts,cvsusers ";
        $sql .= "alerts.sect = '$sect' and alerts.user = cvsusers.user";
        $r = mysql_query($sql, $alink);
+       $elist = array();
        if (!$r) {
                return "";
        } else {
diff --git a/include/functions.inc b/include/functions.inc
index 882f767..cdd2843 100644
--- a/include/functions.inc
+++ b/include/functions.inc
@@ -76,10 +76,10 @@ function foot($secondscreen = null) {
 
 // 
-----------------------------------------------------------------------------------
 
-function hsc($str)             { return 
$GLOBALS['default_filter']?$str:htmlspecialchars($str,ENT_QUOTES,'UTF-8'); }
-function hscr($str)            { return 
htmlspecialchars($str,ENT_QUOTES,'UTF-8'); }
-function strip($var)           { return (get_magic_quotes_gpc() ? 
stripslashes($var) : $var); }
-function escape($var)          { return (get_magic_quotes_gpc() ? $var : 
addslashes($var)); }
+function hsc($str)             { return 
$GLOBALS['default_filter']?$str:htmlspecialchars((string)$str,ENT_QUOTES,'UTF-8');
 }
+function hscr($str)            { return 
htmlspecialchars((string)$str,ENT_QUOTES,'UTF-8'); }
+function strip($var)           { return 
((function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) ? 
stripslashes($var) : $var); }
+function escape($var)          { return 
((function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) ? $var : 
addslashes($var)); }
 function clean($var)           { return 
$GLOBALS['default_filter']?$var:hsc(strip($var)); }
 function format_warn($message) { return "<p class=\"warning\">$message</p>"; }
 function warn($message)        { echo format_warn($message); }
@@ -141,9 +141,15 @@ function array_to_url($array,$overlay=[]) {
         $params[$k] = rawurlencode($k) . "=" . rawurlencode($v);
     }
 
-    return join($params, "&amp;");
+    return implode("&amp;", $params);
 }
 
+/**
+ * @param int $begin
+ * @param int $rows
+ * @param int $skip
+ * @param int $total
+ */
 function show_prev_next($begin, $rows, $skip, $total, $extra = [], $table = 
true)
 {?>
 <?php if ($table): ?>
@@ -453,7 +459,7 @@ function fetch_user($user) {
     $query .= " WHERE users.userid=$user";
   }
   else {
-    $quser = addslashes($user);
+    $quser = addslashes((string)$user);
     $query .= " WHERE username='$quser' OR email='$quser'";
   }
 
diff --git a/include/spam-lib.inc b/include/spam-lib.inc
index 605243e..3085cfa 100644
--- a/include/spam-lib.inc
+++ b/include/spam-lib.inc
@@ -82,7 +82,7 @@ function check_spam_assassin ($text, $sa_path) {
        $spam = shell_exec ('echo ' . escapeshellarg($text) . " | $sa_path -L 
-e 8");
 
        $match = '';
-       if (preg_match ('/^X-Spam-Status:.+(?:\n\t.+)*'.'/m', $spam, $match)) {
+       if (preg_match ('/^X-Spam-Status:.+(?:\n\t.+)*'.'/m', (string)$spam, 
$match)) {
        $spam_data = $match[0];
        } else {
        $spam_data = 'Error matching the SpamAssassin data';
@@ -94,6 +94,7 @@ function check_spam_assassin ($text, $sa_path) {
 // Test with 127.0.0.2 for positive and 127.0.0.1 for negative
 function is_spam_ip ($ip) {
     $reverse_ip = implode('.', array_reverse(explode('.', $ip)));
+    $lists = array();
 
     // spammers lists
     // [0] => dns server, [1] => exclude ip
diff --git a/manage/event.php b/manage/event.php
index f63dde5..1e4694d 100644
--- a/manage/event.php
+++ b/manage/event.php
@@ -7,6 +7,8 @@ define('PHP_SELF', hsc($_SERVER['PHP_SELF']));
 $mailto = "[email protected]";
 #$mailto = "[email protected]";
 
+$days = $months = array();
+
 for ($i = 1; $i <= 7; $i++) {
   $days[$i] = strftime('%A',mktime(12,0,0,4,$i,2001));
 }
diff --git a/manage/github.php b/manage/github.php
index 4ecbceb..76d2fb4 100644
--- a/manage/github.php
+++ b/manage/github.php
@@ -83,7 +83,7 @@ function github_require_valid_user()
 
     $user = github_current_user($gh['access_token']);
 
-    $endpoint = 
'/teams/'.urlencode(GITHUB_PHP_OWNER_TEAM_ID).'/members/'.urlencode($user->login);
+    $endpoint = 
'/teams/'.urlencode((string)GITHUB_PHP_OWNER_TEAM_ID).'/members/'.urlencode($user->login);
     $opts = ['user_agent' => GITHUB_USER_AGENT];
     $ctxt = stream_context_create(['http' => $opts]);
     $is_member = 
file_get_contents('https://api.github.com'.$endpoint.'?access_token='.urlencode($gh['access_token']),
 false, $ctxt);
diff --git a/manage/user-notes.php b/manage/user-notes.php
index 00c397f..da5ace4 100644
--- a/manage/user-notes.php
+++ b/manage/user-notes.php
@@ -339,7 +339,7 @@ if (!$action) {
                "<a href=\"http://php.net/manual/en/{$row['sect']}.php#{$id}\" 
target=\"_blank\">http://php.net/manual/en/{$row['sect']}.php#{$id}</a><br 
/>\n",
                "<a href=\"https://master.php.net/note/edit/$id\"; 
target=\"_blank\">Edit Note</a><br />";
           foreach ($note_del_reasons AS $reason => $text) {
-            echo '<a href="https://master.php.net/note/delete/', $id, '/', 
urlencode($reason), '" target=\"_blank\">', 'Delete Note: ', hscr($text), 
"</a><br />\n";
+            echo '<a href="https://master.php.net/note/delete/', $id, '/', 
urlencode((string)$reason), '" target=\"_blank\">', 'Delete Note: ', 
hscr($text), "</a><br />\n";
           }
           echo "<a href=\"https://master.php.net/note/delete/$id\"; 
target=\"_blank\">Delete Note: other reason</a><br />",
                "<a href=\"https://master.php.net/note/reject/$id\"; 
target=\"_blank\">Reject Note</a>",
diff --git a/manage/users.php b/manage/users.php
index 2f8106a..f0a04e2 100644
--- a/manage/users.php
+++ b/manage/users.php
@@ -9,7 +9,7 @@ require '../include/email-validation.inc';
 require '../include/email-templates.inc';
 
 function csrf_generate(&$mydata, $name) {
-  $mydata["CSRF"][$name] = $csrf = hash("sha512", mt_rand(0,mt_getrandmax()));
+  $mydata["CSRF"][$name] = $csrf = hash("sha512", 
(string)mt_rand(0,mt_getrandmax()));
   return "$name:$csrf";
 }
 function csrf_validate(&$mydata, $name) {
@@ -351,7 +351,7 @@ $res = db_query($query);
 #echo $query;
 
 $res2 = db_query("SELECT FOUND_ROWS()");
-$total = mysql_result($res2,0);
+$total = (int)mysql_result($res2,0);
 
 
 $extra = [
diff --git a/vendor/michelf/php-markdown-extra/markdown.php 
b/vendor/michelf/php-markdown-extra/markdown.php
index f548fc2..820206c 100644
--- a/vendor/michelf/php-markdown-extra/markdown.php
+++ b/vendor/michelf/php-markdown-extra/markdown.php
@@ -239,7 +239,7 @@ class Markdown_Parser {
        var $predef_titles = array();
 
 
-       function Markdown_Parser() {
+       function __construct() {
        #
        # Constructor function. Initialize appropriate member variables.
        #
@@ -931,7 +931,7 @@ class Markdown_Parser {
                if ($matches[2] == '-' && preg_match('{^-(?: |$)}', 
$matches[1]))
                        return $matches[0];
                
-               $level = $matches[2]{0} == '=' ? 1 : 2;
+               $level = $matches[2][0] == '=' ? 1 : 2;
                $block = 
"<h$level>".$this->runSpanGamut($matches[1])."</h$level>";
                return "\n" . $this->hashBlock($block) . "\n\n";
        }
@@ -1227,7 +1227,7 @@ class Markdown_Parser {
                                } else {
                                        # Other closing marker: close one em or 
strong and
                                        # change current token state to match 
the other
-                                       $token_stack[0] = str_repeat($token{0}, 
3-$token_len);
+                                       $token_stack[0] = str_repeat($token[0], 
3-$token_len);
                                        $tag = $token_len == 2 ? "strong" : 
"em";
                                        $span = $text_stack[0];
                                        $span = $this->runSpanGamut($span);
@@ -1252,7 +1252,7 @@ class Markdown_Parser {
                                } else {
                                        # Reached opening three-char emphasis 
marker. Push on token 
                                        # stack; will be handled by the special 
condition above.
-                                       $em = $token{0};
+                                       $em = $token[0];
                                        $strong = "$em$em";
                                        array_unshift($token_stack, $token);
                                        array_unshift($text_stack, '');
@@ -1581,9 +1581,9 @@ class Markdown_Parser {
        # Handle $token provided by parseSpan by determining its nature and 
        # returning the corresponding value that should replace it.
        #
-               switch ($token{0}) {
+               switch ($token[0]) {
                        case "\\":
-                               return $this->hashPart("&#". ord($token{1}). 
";");
+                               return $this->hashPart("&#". ord($token[1]). 
";");
                        case "`":
                                # Search for end marker in remaining text.
                                if 
(preg_match('/^(.*?[^`])'.preg_quote($token).'(?!`)(.*)$/sm', 
@@ -1691,7 +1691,7 @@ class MarkdownExtra_Parser extends Markdown_Parser {
        var $predef_abbr = array();
 
 
-       function MarkdownExtra_Parser() {
+       function __construct() {
        #
        # Constructor function. Initialize the parser object.
        #
@@ -1931,7 +1931,7 @@ class MarkdownExtra_Parser extends Markdown_Parser {
                        #
                        # Check for: Code span marker
                        #
-                       if ($tag{0} == "`") {
+                       if ($tag[0] == "`") {
                                # Find corresponding end marker.
                                $tag_re = preg_quote($tag);
                                if 
(preg_match('{^(?>.+?|\n(?!\n))*?(?<!`)'.$tag_re.'(?!`)}',
@@ -1967,7 +1967,7 @@ class MarkdownExtra_Parser extends Markdown_Parser {
                        #
                        # Check for: Indented code block.
                        #
-                       else if ($tag{0} == "\n" || $tag{0} == " ") {
+                       else if ($tag[0] == "\n" || $tag[0] == " ") {
                                # Indented code block: pass it unchanged, will 
be handled 
                                # later.
                                $parsed .= $tag;
@@ -1995,7 +1995,7 @@ class MarkdownExtra_Parser extends Markdown_Parser {
                        #            HTML Comments, processing instructions.
                        #
                        else if 
(preg_match('{^<(?:'.$this->clean_tags_re.')\b}', $tag) ||
-                               $tag{1} == '!' || $tag{1} == '?')
+                               $tag[1] == '!' || $tag[1] == '?')
                        {
                                # Need to parse tag and following text using 
the HTML parser.
                                # (don't check for markdown attribute)
@@ -2014,8 +2014,8 @@ class MarkdownExtra_Parser extends Markdown_Parser {
                                #
                                # Increase/decrease nested tag count.
                                #
-                               if ($tag{1} == '/')                             
                $depth--;
-                               else if ($tag{strlen($tag)-2} != '/')   
$depth++;
+                               if ($tag[1] == '/')                             
                $depth--;
+                               else if ($tag[strlen($tag)-2] != '/')   
$depth++;
 
                                if ($depth < 0) {
                                        #
@@ -2119,7 +2119,7 @@ class MarkdownExtra_Parser extends Markdown_Parser {
                                # first character as filtered to prevent an 
infinite loop in the 
                                # parent function.
                                #
-                               return array($original_text{0}, 
substr($original_text, 1));
+                               return array($original_text[0], 
substr($original_text, 1));
                        }
                        
                        $block_text .= $parts[0]; # Text before current tag.
@@ -2131,7 +2131,7 @@ class MarkdownExtra_Parser extends Markdown_Parser {
                        #                        Comments and Processing 
Instructions.
                        #
                        if 
(preg_match('{^</?(?:'.$this->auto_close_tags_re.')\b}', $tag) ||
-                               $tag{1} == '!' || $tag{1} == '?')
+                               $tag[1] == '!' || $tag[1] == '?')
                        {
                                # Just add the tag to the block as if it was 
text.
                                $block_text .= $tag;
@@ -2142,8 +2142,8 @@ class MarkdownExtra_Parser extends Markdown_Parser {
                                # the tag's name match base tag's.
                                #
                                if (preg_match('{^</?'.$base_tag_name_re.'\b}', 
$tag)) {
-                                       if ($tag{1} == '/')                     
                        $depth--;
-                                       else if ($tag{strlen($tag)-2} != '/')   
$depth++;
+                                       if ($tag[1] == '/')                     
                        $depth--;
+                                       else if ($tag[strlen($tag)-2] != '/')   
$depth++;
                                }
                                
                                #
@@ -2267,7 +2267,7 @@ class MarkdownExtra_Parser extends Markdown_Parser {
        function _doHeaders_callback_setext($matches) {
                if ($matches[3] == '-' && preg_match('{^- }', $matches[1]))
                        return $matches[0];
-               $level = $matches[3]{0} == '=' ? 1 : 2;
+               $level = $matches[3][0] == '=' ? 1 : 2;
                $attr  = $this->_doHeaders_attr($id =& $matches[2]);
                $block = 
"<h$level$attr>".$this->runSpanGamut($matches[1])."</h$level>";
                return "\n" . $this->hashBlock($block) . "\n\n";
@@ -2929,4 +2929,4 @@ negligence or otherwise) arising in any way out of the 
use of this
 software, even if advised of the possibility of such damage.
 
 */
-?>
\ No newline at end of file
+?>
-- 
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to