简体   繁体   中英

PHP 5.2 app using Codeigniter upgrade to 6.7

I've been giving the task to upgrade an old PHP Web app that is written in php 5.2.17 and using Codeigniter. Doing my upgrade from PHP 5.2 to 5.6 I've been running into to some errors. At a first glance it looks like the problems might be a mix of using old PHP syntax as well as some issues with Codeigniter. I have never worked with Codeigniter which is making this task incredible hard. The problems occurs on a page where you can edit some already existing data on a patient and then submit the new updated data. Pretty much a CRUD.
The crud has been working completely fine on a server supporting > 5.6 PHP, but now that I have transferred to a server that only supports < 5.6 PHP, I've been getting these problems.

First problem: On the form page I get these two errors and the data inside of those variables are not displayed on the page. If I decide to submit the new entered data the new data are not saved as well.

1) Trying to get property of non-object 2) Undefined variable: rows The page errors lets me know that my error occurs at around these lines:

        $anatomic_code = $rows->NerveCode;
        $ProxAccess = $rows->ProxAccess;
        $DistAccess = $rows->DistAccess;

From reading documentation from Codeigniter I was suggested to use [''] to access the data, if I do the error message "Trying to get property of non-object" goes away, but I still have the second error and still not seeing the data on the page.

Here is a bigger snippet of the code:

<div id="wrapper"> 
    <?

    $exam_id = $this->uri->segment(3);
    $struct_id = $this->uri->segment(4);   
    $struct_type = $this->uri->segment(5);
    $tech_id = $this->uri->segment(6);
    $test_id = $this->uri->segment(7);
    $TechName = $query_tech_type->row();
    $side = $query_side->row();

    //Update form
    $hidden = array(
        'Exam' => $exam_id,
        'Struct_id' => $struct_id,
        'Structure_type' => $struct_type,
        'Tech_id' => $tech_id,
        'Test' => $test_id
    );
    ?>

    <a href="<? echo site_url("auh/show_ind_patient/".$exam_id.""); ?> "><img src="<? echo base_url() . "public/holder/back.png"; ?>" border="0" title="Back to test page"></a>

    <?
    echo form_open("auh/update_enkel_test_values/","", $hidden);

    echo "<h2>" . $TechName->Tech_name . "</h2>";

    echo "<div id=\"tech_no\" style=\"display:none\">".$tech_id."</div>";

    if ($struct_id == "1"){
            foreach($query->result() as $rows):
                echo "<h3>M." . $rows->MuscleName . ") (" . $side->SideText.")</h3>";
            endforeach;
            $anatomic_code = $rows->MuscleCode; 
    }

    elseif ($struct_id == "2") {

            foreach($query->result() as $rows): 
                echo "<h3>N." . $rows->NerveName . ") (" . $side->SideText.")</h3>";
            endforeach;
            $anatomic_code = $rows->NerveCode; 
    }

    elseif ($struct_id == "3") {

            foreach($query->result() as $rows):
            if ($rows->NerveCode > 10000 ){
                echo "<h3>N." . $rows->NerveName . ") (" . $side->SideText.")</h3>";        

            }
            else {
                echo "<h3>N." . $rows->NerveName . " (" . $rows->ProxName . " - ";
                    if ($rows->Code < 3000) {
                        echo "m.";
                        }
                    echo $rows->DistName . ") ("  . $side->SideText.")</h3>";
            }
            endforeach;
            $anatomic_code = $rows->NerveCode;
            $ProxAccess = $rows->ProxAccess;
            $DistAccess = $rows->DistAccess;
    }

    elseif ($struct_id == "4"){ 
            foreach($query->result() as $rows):
                $anatomic_code = $rows->NerveCode;
                if ($rows->NerveCode > 10000 ){
                    echo "<h3>" . $rows->NerveName . " (". $side->SideText .")</h3>";    
                }
                else{
                    echo "<h3>N." . $rows->NerveName . " - m." . $rows->MuscleName . " (". $side->SideText .")</h3>";
                }
            endforeach;
    }

Look through the backwards incompatible changes in the PHP documentation:

https://secure.php.net/manual/en/migration53.php

https://secure.php.net/manual/en/migration54.php

https://secure.php.net/manual/en/migration55.php

https://secure.php.net/manual/en/migration56.php

Go through each of those and do a find and replace through your codebase. Then you'll be on 5.6. But don't stop there! ;-)

https://secure.php.net/manual/en/migration70.php

https://secure.php.net/manual/en/migration71.php

https://secure.php.net/manual/en/migration72.php

You will find you have less and less things to change with each subsequent upgrade. 5.2 to 5.3 and to 5.4 probably have the most work involved.

You should try and get on version 7.2, the reason being that 5.6 is currently only developing security fixes, and is no longer going to be supported from Jan 1st 2019. Check this link here:

https://secure.php.net/supported-versions.php

Also, you can upgrade your Codeigniter installation. I don't know which version of codeigniter you are using, but you should download the latest version and follow their guide:

https://www.codeigniter.com/userguide3/installation/upgrading.html

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM