PHPスクリプトから、あるクラスから別のクラスを介して変数にアクセスしようとしています:
私の最初のクラスは次のとおりです。
クラスデータ{
private $length;
private $height;
public function setLength($length){
$this->length = $length;
}
public function getLength(){
return $this->length;
}
public function setHeight($height){
$this->height = $height;
}
public function getHeight(){
return $this->height;
}
}
私は別のクラスを持っています:
class proccess extends data{
public function getOrientation(){
if($this->getLength() > $this->getHeight()) {
$orientation = 'landscape';
} else {
$orientation = 'portrait';
}
}
}
クラス プロセスから $this->getLenght() または $this-getHeight() にアクセスしようとすると、値が空になります。次のように、phpスクリプトを使用して値を設定しています。
<?php
require_once('functions/data.php');
require_once('functions/process.php');
$data=new data();
$process = new process();
$data->setLength(25);
$data->setHeight(30);
$orientation = $process->getOrientation();
関数 getOrientation が幅と長さの値を取得できない理由と、これを修正する方法についてのアイデアはありますか?