heberekeの日記: クラス内で別クラスを参照する
日記 by
hebereke
<?php
class Foo
{
function hoge($var)
{
print "hello, $var";
}
}
class Bar
{
var $ref; // reference to instance
// Constractor
function Bar(&$ref)
{
$this->ref = $ref;
}
// e.g
function huni($var)
{
$this->ref->hoge($var);
}
}
$objFoo = new Foo;
$objBar = new Bar($objFoo);
$var = 'World';
// execute Foo::hoge() through Bar
$objBar->huni($var);
?>
webStudio で遊んでみるテスト.
これで二つ以上のクラスをからめて使えるっぽ.
ただOOPのことは全然分からないものの依存べたべたな時点で何か間違っている気がしなくもない..
class Foo
{
function hoge($var)
{
print "hello, $var";
}
}
class Bar
{
var $ref; // reference to instance
// Constractor
function Bar(&$ref)
{
$this->ref = $ref;
}
// e.g
function huni($var)
{
$this->ref->hoge($var);
}
}
$objFoo = new Foo;
$objBar = new Bar($objFoo);
$var = 'World';
// execute Foo::hoge() through Bar
$objBar->huni($var);
?>
webStudio で遊んでみるテスト.
これで二つ以上のクラスをからめて使えるっぽ.
ただOOPのことは全然分からないものの依存べたべたな時点で何か間違っている気がしなくもない..
クラス内で別クラスを参照する More ログイン