how insert method in class from another file? Now i get error:
`T_FUNCTION' in C:\wamp\www\index.php on line 9
index.php file:
<?php
class cars
{
public function go()
{
echo 'go go';
}
include('stop.php');
}
$c = new cars;
$c->go();
?>
stop.php file
<?php
public function stop()
{
echo 'stop method';
}
?>
What you are trying to do is not possible in PHP.
You would have to create multiple classes that extend each other:
class cars_base
{....}
stop.php:
class cars_base_1 extends cars_base
{....}
but this is rarely practical. Much rather try to build an object structure that is easy to split into separate modules that do not need to extend each other - or, if it clearly belongs into the same class, live with a lot of code in one file. With a good IDE, that's not that much of a problem.
This is not possible in PHP, include doesn't work like a macro.
PHP 5.4 will support Traits, which offer what you want. But in the current stable version of PHP best you cen do is inheritance ;)