Skip to content

php 8.5: fix deprecated 'double' -> 'float'#547

Closed
tenzap wants to merge 1 commit into
kalkun-sms:develfrom
tenzap:feature-226-php85
Closed

php 8.5: fix deprecated 'double' -> 'float'#547
tenzap wants to merge 1 commit into
kalkun-sms:develfrom
tenzap:feature-226-php85

Conversation

@tenzap

@tenzap tenzap commented Aug 17, 2025

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes

    • Improved initialization of randomness used for nonce generation in the SMS-to-XMPP integration, enhancing reliability and consistency across environments. No changes to user-facing behavior or public APIs.
  • Chores

    • Internal maintenance to strengthen random number seeding logic for future stability and compatibility.

@coderabbitai

coderabbitai Bot commented Aug 17, 2025

Copy link
Copy Markdown

Walkthrough

Changed RNG seeding precision in JAXL utility: generateNonce now uses a float cast for microtime when seeding my_mt_srand; nonce generation loop unchanged. No public API or signature changes.

Changes

Cohort / File(s) Summary
RNG seeding adjustment
application/plugins/sms_to_xmpp/libraries/abhinavsingh-JAXL-5829c3b/core/jaxl.util.php
In generateNonce, changed seed cast from (double) to (float) for my_mt_srand(microtime()*10000000); nonce generation logic unchanged.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (2)
application/plugins/sms_to_xmpp/libraries/abhinavsingh-JAXL-5829c3b/core/jaxl.util.php (2)

154-160: Use a CSPRNG for nonce generation (random_bytes / Randomizer->getBytes).

Nonce material should be unpredictable. The current approach is based on MT (non-cryptographic). Prefer random_bytes (available since PHP 7.0), and fall back to the existing logic only if unavailable.

Apply this diff:

-        public static function generateNonce() {
-            $str = '';
-            my_mt_srand((float) microtime()*10000000);
-            for($i=0; $i<32; $i++)
-                $str .= chr(my_mt_rand(0, 255));
-            return $str;
-        }
+        public static function generateNonce() {
+            // Prefer cryptographically secure RNG when available
+            if (function_exists('random_bytes')) {
+                return random_bytes(32);
+            }
+            $str = '';
+            my_mt_srand((int) (microtime(true) * 10000000));
+            for ($i = 0; $i < 32; $i++) {
+                $str .= chr(my_mt_rand(0, 255));
+            }
+            return $str;
+        }

188-200: pbkdf2 is broken: undefined variables ($s, $p, $c) and wrong return var ($dk_len).

This function cannot work as written and will produce errors. Fix variable names and logic to match the signature.

-        public static function pbkdf2($data, $secret, $iteration, $dkLen=32, $algo='sha1') {
-            $hLen = strlen(hash($algo, null, true));
-            
-            $l = ceil($dkLen/$hLen);
-            $t = null;
-            for($i=1; $i<=$l; $i++) {
-                $f = $u = hash_hmac($algo, $s.pack('N', $i), $p, true);
-                for($j=1; $j<$c; $j++)
-                    $f ^= ($u = hash_hmac($algo, $u, $p, true));
-                $t .= $f;
-            }
-            return substr($t, 0, $dk_len);
-        }
+        public static function pbkdf2($salt, $password, $iterations, $dkLen = 32, $algo = 'sha1') {
+            $hLen = strlen(hash($algo, '', true));
+            $l = (int) ceil($dkLen / $hLen);
+            $t = '';
+            for ($i = 1; $i <= $l; $i++) {
+                $f = $u = hash_hmac($algo, $salt . pack('N', $i), $password, true);
+                for ($j = 1; $j < $iterations; $j++) {
+                    $u = hash_hmac($algo, $u, $password, true);
+                    $f ^= $u;
+                }
+                $t .= $f;
+            }
+            return substr($t, 0, $dkLen);
+        }
🧹 Nitpick comments (2)
application/plugins/sms_to_xmpp/libraries/abhinavsingh-JAXL-5829c3b/core/jaxl.util.php (2)

154-160: Seed RNG with an integer and use microtime(true) to avoid string-to-float casts.

Casting the default string return of microtime() to float is unnecessary; microtime(true) returns a float directly. Also, seeding with an int avoids implicit float-to-int conversion in both mt_srand and Random\Engine\Mt19937.

Apply this minimal diff:

-            my_mt_srand((float) microtime()*10000000);
+            my_mt_srand((int) (microtime(true) * 10000000));

53-67: Guard against partially specified bounds in my_mt_rand.

If only one of $min/$max is provided, getInt will receive null for the other bound (TypeError). mt_rand also requires both bounds or neither. Add validation to enforce "both or none".

 function my_mt_rand($min = null, $max = null) {
     if (version_compare(PHP_VERSION, '8.2.0') >= 0) {
         if (!isset($GLOBALS['my_mt_rand'])) {
             $GLOBALS['my_mt_rand'] = new \Random\Randomizer(new \Random\Engine\Mt19937());
         }
 
-        if ($min === null && $max === null) {
-            return $GLOBALS['my_mt_rand']->nextInt();
-        }
-
-        return $GLOBALS['my_mt_rand']->getInt($min, $max);
+        if ($min === null && $max === null) {
+            return $GLOBALS['my_mt_rand']->nextInt();
+        }
+        if ($min !== null && $max !== null) {
+            return $GLOBALS['my_mt_rand']->getInt($min, $max);
+        }
+        throw new \InvalidArgumentException('Both $min and $max must be provided, or neither.');
     } else {
         return mt_rand($min, $max);
     }
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7bbf8bf and 7ccd41b.

📒 Files selected for processing (1)
  • application/plugins/sms_to_xmpp/libraries/abhinavsingh-JAXL-5829c3b/core/jaxl.util.php (1 hunks)
🔇 Additional comments (1)
application/plugins/sms_to_xmpp/libraries/abhinavsingh-JAXL-5829c3b/core/jaxl.util.php (1)

156-156: LGTM: replace deprecated (double) cast with (float).

This aligns with PHP 8.x deprecations and preserves existing behavior.

@tenzap

tenzap commented Oct 16, 2025

Copy link
Copy Markdown
Collaborator Author

@kingster ?

@tenzap

tenzap commented Oct 28, 2025

Copy link
Copy Markdown
Collaborator Author

Added to #549

@tenzap tenzap closed this Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant