Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix float to int conversion error #188

Merged
merged 4 commits into from
Mar 9, 2023

Conversation

Sebbo94BY
Copy link
Collaborator

Fixes the following error: Implicit conversion from float to int loses precision

Exception:

   Whoops\Exception\ErrorException 

  Implicit conversion from float 1678058856.0934 to int loses precision

  at vendor/planetteamspeak/ts3-php-framework/src/Helper/Profiler/Timer.php:93
     89▕
     90▕         $this->data["realmem_start"] = memory_get_usage(true);
     91▕         $this->data["emalloc_start"] = memory_get_usage();
     92▕
  ➜  93▕         $this->started = microtime(true);
     94▕         $this->running = true;
     95▕     }
     96▕
     97▕     /**

      +3 vendor frames 
  4   [internal]:0
      PlanetTeamSpeak\TeamSpeak3Framework\Adapter\ServerQuery::__destruct()

Fixes the following error: `Implicit conversion from float to int loses precision`
@ronindesign
Copy link
Collaborator

There's no point in using microtime(true) if we don't want float, i.e. microseconds, since intval() will just truncate of the microseconds information and result in just "seconds".

Since microtime(true) is set explicitly and I believe intentionally, the fix should be to change the initial types from int to float so there's no type conversion.

Class variable was initialized as int, but then used in float arithmetic. Init type changed from int to float.
Copy link
Collaborator

@ronindesign ronindesign left a comment

Choose a reason for hiding this comment

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

Using intval() would result in truncation of microtime() to just seconds, defeating the purpose.

I've updated init type of $this->started to float so there's no implicit conversion.

@ronindesign ronindesign merged commit 3d06c49 into planetteamspeak:dev Mar 9, 2023
@Sebbo94BY Sebbo94BY deleted the Fix-conversion-error branch March 9, 2023 22:01
@Sebbo94BY
Copy link
Collaborator Author

Ok, probably the better solution. 😅

Thanks for updating and merging it!

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.

2 participants