Cara menggunakan php deprecated functions

Deprecated: Array and String offset access syntax with curly braces is deprecated in/var/xxx/xxx/xx/xx/xxx on line xxxx"


untuk mengatasi kendalanya tersebut, bisa mengikuti langkah langkah berikut :

di check kembali pada file mana yang mengalami keterangan eror pada saat diaksesnya website anda, sebagai contoh, eror pada file a.php on line 135 dengan isi 

scriptnya sebagai berikut : 

PHP

public function getRecordID(string $zoneID, string $type = '', string $name = ''): string
{    
    $records = $this->listRecords($zoneID, $type, $name);   
    if (isset($records->result{0}->id)
    {       
         return $records->result{0}->id;    
    }    
return false;

}

PHP

*untuk errornya pada script dengan tulisan tebal dan miring

silahkan untuk melakukan perubahan pada script yang ditandai menjadi berikut 

PHP

public function getRecordID(string $zoneID, string $type = '', string $name = ''): string
{    
        $records = $this->listRecords($zoneID, $type, $name);    
        if (isset($records->result[0]->id)
        {        
            return $records->result[0]->id;    
        }    
return false; 
}


*untuk perbaikan pada script dengan tulisan tebal dan miring

setelah itu klik save, dan silahkan dicoba kembali untuk pengaksesan website anda.


untuk instalasi dari PHP Code Fixer sendiri, sangat mudah jika dilakukan dengan Composer. (Untuk apa itu composer dan cara installnya silakan baca disini).

[sourcecode]
composer require wapmorgan/php-code-fixer
[/sourcecode]

Kemudian lakukan composer update:
[sourcecode]
composer update
[/sourcecode]

atau kalau malas menggunakan composer, silakan download repository-nya sebagai file Zip di https://github.com/wapmorgan/PhpCodeFixer/archive/master.zip

Penggunaan

Dari dokumentasinya didapatkan penjelasan sbb:
[sourcecode]
Usage: phpcf [–target VERSION] [–max-size SIZE] FILES…

Options:
-t, –target VERSION target php version [default: 7.1]
-s, –max-size SIZE sets max size of php file. If size of file is above this value, file will be skipped [default: 1mb]
[/sourcecode]

dengan parameter target (versi PHP yang dituju) dan size (ukuran file PHP).

Versi PHP yang didukung saat ini:

  • PHP versi 7.1
  • PHP versi 7.0
  • PHP versi 5.6
  • PHP versi 5.5
  • PHP versi 5.4
  • PHP versi 5.3

Contohnya:
[sourcecode]
php bin/phpcf –target 7.1 /path/ke/folder/sisteminformasi
[/sourcecode]

Contoh hasil:

~/tools/vendor/bin$ php phpcf --target 7.1 /home/subdomain/psbonlinefree/
Max file size set to: 1.000 MiB
Scanning /home/subdomain/psbonlinefree/ ...
 PHP |             Type |                      File:Line | Issue
 5.5 | function         | ...onlinefree//modul/10.php:34 | Function mysql_query is deprecated.
 5.5 | function         | ...onlinefree//modul/10.php:50 | Function mysql_fetch_array is deprecated.
 5.5 | function         | ...onlinefree//modul/11.php:30 | Function mysql_query is deprecated.
 5.5 | function         | ...onlinefree//modul/11.php:31 | Function mysql_fetch_array is deprecated.
 5.5 | function         | ...onlinefree//modul/12.php:38 | Function mysql_query is deprecated.
 5.5 | function         | ...onlinefree//modul/12.php:40 | Function mysql_fetch_array is deprecated.
 5.5 | function         | ...onlinefree//modul/14.php:31 | Function mysql_query is deprecated.
 5.5 | function         | ...onlinefree//modul/14.php:47 | Function mysql_fetch_array is deprecated.
 5.5 | function         | ...onlinefree//modul/15.php:33 | Function mysql_query is deprecated.
 5.5 | function         | ...bonlinefree//modul/2.php:41 | Function mysql_query is deprecated.
 5.5 | function         | ...bonlinefree//modul/2.php:43 | Function mysql_fetch_array is deprecated.
 5.5 | function         | ...bonlinefree//modul/3.php:70 | Function mysql_fetch_array is deprecated.
 5.5 | function         | ...bonlinefree//modul/3.php:70 | Function mysql_query is deprecated.
 5.5 | function         | ...onlinefree//modul/3.php:118 | Function mysql_query is deprecated.
 5.5 | function         | ...bonlinefree//modul/5.php:44 | Function mysql_query is deprecated.
 5.5 | function         | ...bonlinefree//modul/5.php:45 | Function mysql_num_rows is deprecated.
 5.5 | function         | ...bonlinefree//modul/5.php:48 | Function mysql_fetch_array is deprecated.
 5.5 | function         | ...bonlinefree//modul/8.php:31 | Function mysql_query is deprecated.
 5.5 | function         | ...bonlinefree//modul/8.php:47 | Function mysql_fetch_array is deprecated.
 5.5 | function         | ...bonlinefree//modul/9.php:33 | Function mysql_query is deprecated.
 5.5 | function         | ...nefree//modul/fungsi.php:51 | Function mysql_fetch_array is deprecated.
 5.5 | function         | ...nefree//modul/fungsi.php:51 | Function mysql_query is deprecated.
 5.5 | function         | ...e//modul/konfigurasi.php:48 | Function mysql_connect is deprecated.
 5.5 | function         | ...e//modul/konfigurasi.php:51 | Function mysql_select_db is deprecated.

Replace Suggestions:
1. Don't use function mysql_connect. Instead use mysqli::__construct
Peak memory usage: 1.536 MB

Disana ada banya fungsi deprecated di PHP 7.1, jika ingin tetap dimigrasi, ada pula saran yang diberikan.