Hi,

i have class "User_registration" and in this class i need use many class: "Location", "Links", "Mail", "Module".

i create include all class in file: include 'class/location.php'; include 'class/links.php'; include 'class/mail.php'; include 'class/modules.php';

Now create "User_registration" class.

<?php
class User_registration{

    public function insert_to_db($name, $country_code, $home_page)
    {
        //work with data

        return id;
    }

    public function show_info($id)
    {
        //work with data
    }

}

$reg_u = new User_registration;
$res = $reg_u->insert_to_db($name, $country_code, $home_page);

if($res){
    $reg_u->show_info($res);
}
?>

I need in method "insert_to_db" run class: "Location", "Links", "Mail" methods and in "show_info" run some methods of "Location", "Links", "Module" class.

How? How in one class run another class (no't one)

Thanks for help ;)

You need to create all class files with .class.php extension like:

Test1.class.php
Test2.class.php
Test3.class.php

Assume these three classes are in lib directory.

and include these class files into your another class file Test4.class.php like :
Test4.class.php:

include_once('/lib/Test1.class.php');
include_once('/lib/Test2.class.php');
include_once('/lib/Test3.class.php');

and create objects :

$test1 = new Test1();
$test2 = new Test2();
$test3 = new Test3();

// can call class methods like:
$test1->get_data();

There is absolutely no need to create your class files with a .class.php extension, or any special naming convention.

However, many of the larger projects these days have moved to the PEAR standard for naming classes (http://pear.php.net/manual/en/standards.naming.php). This is completely optional of course.

I don't quite understand your question fully as it is very open ended. Are you simply asking how you would use a class within a function of another class, or are your location, links etc classes parts of the User_Registration class? e.g. User_Registration is composed of a "location" (instance of Location) and composed of n "links" (array of Link objects) etc?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.