0

how in one class use another class? My code is correct?

<?php
class Country{
    function countryById($id)   {
        echo $id;
    }

}
class Validate{
    function text($id)  {
        return true;
    }

}
class Register{

    function write($name, $url, $country){
        $val = new Validate();
        $c_id = new Country();

        if(!$val->text($name))
          return false;

        $country_id = $c_id->countryById($country);
        }
}


$r = new Register();
$r->write('test', 'www.google.com', 'france');
?>
1
  • 1
    Please rephrase your question and add more context about what it actually is you are trying to do. Also, the code sample you provided will most likely not work as it contains syntax errors. Please post valid code so that we can answer your question properly. Commented Dec 21, 2010 at 8:35

1 Answer 1

1

almost. except $val = new Validate; right syntax is $val = new Validate(); and include function expects string literal or variable (include ('class/myclass.php'))

Sign up to request clarification or add additional context in comments.

1 Comment

$val = new Validate; is fine. You can omit the brackets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.