を含め、私は、次の質問を持っている:PHPのクラスとは
これは私のメインのファイルindex.php
です。
<?php
class myClass
{
function myClass()
{
echo '[constructor]';
$this->myVar = '[i am making a test]';
$this->A();
}
function A()
{
echo '[function A works too]';
echo $this->myVar;
}
}
$test = new myClass;
?>
今私はメインファイルにのinclude_once、私は可能性が別のPHPファイルincludes/function_a.php
にfunction A
を移動する必要があります。その理由は、メインファイルを小さくして読みやすくするためです。
これを実行するベストプラクティスは何ですか、EXTENDS?
EDIT:
私が使用してこれをやったが延び:
のindex.php
<?php
include_once('includes/function_a.php');
class myClass extends anotherClass
{
function myClass()
{
echo '[constructor]';
$this->myVar = '[i am making a test]';
$this->A();
}
}
$test = new myClass;
?>
は、/ function_a.php
<?php
class anotherClass
{
function A()
{
echo '[function A works too]';
echo $this->myVar;
}
}
?>
をもっと良いアイデアですか?
'関数A 'を別のファイルに入れたいのに、まだ' myClass'クラスの一部ですか? –
最終的に一度に読む必要があるものを分割するのはなぜですか? – Alfabravo
はい、私は関数A全体を別のファイルに配置したいが、メインクラスの内部にあるのと同じ機能を持たせたい。 – acoder