Bir ilişkisel dizi düz bir PHP sınıfı Dizgeleştirme

0 Cevap

Basit bir sınıf düşünün:

class Token{
    private $hash = "";
    private $userId = "";

    public function  __construct($hash, $userId) {
        $this->hash = $hash;
        $this->userId = $userId;
    }

    public function getHash() {
        return $this->hash;
    }

    public function getUserId() {
        return $this->userId;
    }

    public function setHash($hash) {
        $this->hash = $hash;
    }

    public function setUserId($userId) {
        $this->userId = $userId;
    }
}

Böylece gibi, bir ilişkisel dizi için getirilmeye çalışılıyor:

// the token
$t = new Token("sampleHash", "sampleUser");

// an array for comparison
$retObj = array();
$retObj['hash']   = $t->getHash();
$retObj['userId'] = $t->getUserId();

print_r((array) $t);
echo "<br>";
print_r($retObj);

Ben bu olsun:

Array ( [�Token�hash] => sampleHash [�Token�userId] => sampleUser )
Array ( [hash] => sampleHash [userId] => sampleUser )

Ne oluyor? Ben ikinci baskı hattı gibi bakmak serileştirme nasıl düzeltebilirim?

0 Cevap