1

I want to preview pdf, but not open after updated to php 8 and some package update.
This code notif from laravel

function konversi($x)

    {

        $x = abs($x);

        $angka = array("", "Satu", "Dua", "Tiga", "Empat", "Lima", "Enam", "Tujuh", "Delapan",   "Sembilan", "Sepuluh", "Sebelas");

        $temp = "";

 
> if ($x < 12) {// Notif from laravel in this line


            $temp = " " . $angka[$x];

        } else if ($x < 20) {

            $temp = konversi($x - 10) . " Belas";

        } else if ($x < 100) {

            $temp = konversi($x / 10) . " Puluh" . konversi($x % 10);

        } else if ($x < 200) {

            $temp = " Seratus" . konversi($x - 100);

        } else if ($x < 1000) {

            $temp = konversi($x / 100) . " Ratus" . konversi($x % 100);

        } else if ($x < 2000) {

            $temp = " Seribu" . konversi($x - 1000);

        } else if ($x < 1000000) {

            $temp = konversi($x / 1000) . " Ribu" . konversi($x % 1000);

        } else if ($x < 1000000000) {

            $temp = konversi($x / 1000000) . " Juta" . konversi($x % 1000000);

And this notif preview, Type Error

abs(): Argument #1 ($num) must be of type int|float, string given (View: C:\Users\Fauzan Azhim\Downloads\sci-tkdn-fixing_laporan\sci-tkdn-fixing_laporan\resources\views\laporan\cetak_permen_1.blade.php)

Passerby
  • 9,715
  • 2
  • 33
  • 50
Azhimy Fzn
  • 33
  • 1
  • 2
  • 6
  • As the error message says, you passed a string to a function that expected an integer or float. Please see: [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – IMSoP Apr 01 '22 at 15:01

1 Answers1

2

abs(): Argument #1 ($num) must be of type int|float, string given (View: C:\Users\Fauzan Azhim\Downloads\sci-tkdn-fixing_laporan\sci-tkdn-fixing_laporan\resources\views\laporan\cetak_permen_1.blade.php)

  1. The error comes from your blade file.
  2. change in this blade file abs($num) to abs((int) $num)
  3. Try again.
Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79
  • 'function konversi($x) { $x = abs((int) $x) ' int? with number or int just like that? – Azhimy Fzn Apr 02 '22 at 02:58
  • @AzhimyFzn it depeds what you are expect. But in your case it would be a int. but can you dump out $x and share it, please? `dump($x);`. Put the dump on top in your function. – Maik Lowrey Apr 02 '22 at 05:38