Search code examples
phpjavascriptjqueryclassprivate-methods

PHP Class private variable misdirected value


first of all, my problem is from my php class called by a php file who is accessed by an AJAX call.

The problem is that the return value is totally wrong and is not the same as the sybase_result value. So what am i missing?

Here are the steps of my program.

First we make the AJAX call:

$.ajax(
{
    type: "POST",
    url: "ajax/load_fiche_resume.php",
    timeout:5000,
    dataType: 'json',
    data: ({matricule:matricule, id_mun:id_mun}),
    beforeSend: function()
    {
        // Handle the beforeSend event
        $('#loading-bar').show("slow");
    },
    complete: function()
    {
        // Handle the complete event
        $('#loading-bar').hide("slow");

    },
    success: function(data)
    {

        console.dir(data);

        $('#tab-role').html(formatData(data));
    },
    error: function () 
    {
        alert("Oops! Une erreur c'est produite.\nVeuiller rafraichir la page. \nSi cela se reproduit, veuiller contacter le propriétaire du site.");
    }
});

Then, we go into the php file load_fiche_resume.php

include('../class/class_role.php');

$oRole = new Role("42025", "2036-94-5034");


$ar_step2 = array(
                array("Propriétaire(s)"),
                array("Nom(s) : ", $oRole->getProprioNoms() ),
                array("Adresse postale : ", $oRole->getProprioAdresse() ),
                array("Condition particulière d'inscription : ", $oRole->getProprioCondition() ),
                array("Date d'inscription au rôle : ", $oRole->getProprioDateInscription() )
            );

If we look closer at the code above, the return value of the function $oRole->getProprioDateInscription() is supposed to be a date. But instead of a date, this function return a string from another get function(i.e.: it will show the valu of $oRole->getProprioNoms) and it is totally wrong.

If we go inside the class $oRole we have this:

class Role
{
    private $prop_inscription;
    public function getInfoProprio()
    {
        $qry = "SELECT 
                    p.nom_form AS nom_form,
                    p.t_typos AS t_typos,
                    substr(p.d_date_inscr,1,10) AS d_date_inscr,
                    pga.adr_form AS adr_form,
                    p.id_adr AS id_adr,
                    p.id AS id
                FROM 
                    ev_dossiers d,
                    ro_b75 p,
                    pg_adresses pga
                WHERE 
                    d.id_dossiers = ".$this->getIdDossier()." AND
                    d.typ_donnees = 11 AND
                    d.id_donnees = p.id AND
                    p.id_adr = pga.id_adr order by p.id, p.id_adr, p.ordre;";
        $this->prop_qry = $qry;
        $result = sybase_query($qry, $this->getLinkDB());
        $nbr = sybase_num_rows($result);
        $typos = sybase_result($result, 0, "t_typos");

        if($nbr>0)
        {
            for($cpt=0; $cpt<$nbr; $cpt++)
            {
                if($cpt===0)
                {
                    $this->setProprioNoms(utf8_encode(strtr(trim(sybase_result($result, $cpt, "nom_form")),"’","'")));
                    $this->setProprioAdresse(utf8_encode(strtr(trim(sybase_result($result, $cpt, "adr_form")),"’","'")));
                    $this->setProprioCondition($this->getConditionInscription(sybase_result($result, $cpt, "t_typos")));

// THIS IS PROBLEMATIC                       
$this->setProprioDateInscription(sybase_result($result, 0, "d_date_inscr"));
                }
                else 
                {
                    $this->setProprioNoms(", ".utf8_encode(strtr(trim(sybase_result($result, $cpt, "nom_form")),"’","'")));
                }
            }
        }
    }   

    ...

        public function getProprioDateInscription()
    {
        return $this->prop_inscription;
    }
    private function setProprioDateInscription($date)
    {
        $this->prop_inscription = $date;
    }
}

If we have look at the line where we have this : $this->setProprioDateInscription(sybase_result($result, 0, "d_date_inscr"));

The sybase_result return a date (it's all OK from the database and the value is good). But the problem is between the Setter and the Getter of the private var prop_inscription.

Can you help me? Do you know where is the problem from?

Thank you very much.


Solution

  • To resolve this,

    juste change this line

    // THIS IS PROBLEMATIC                       
    $this->setProprioDateInscription(sybase_result($result, 0, "d_date_inscr"));
    

    to

    $this->setProprioDateInscription(utf8_encode(strtr(trim(sybase_result($result, $cpt,"d_date_inscr")),"’","'")));