Code example:
<?php // class_database.php
class database
{
include("class_validation.php"); //this does not work
$val = new validation() //this does not work
public function login($value)
{
if($val->validate($value))
{
//do something
}
}
}
<?php // class_validation.php
class validation
{
public function validate($value)
{
if($value > 50) return true;
return false;
}
}
How do I delegate the class validation in class database?
I do not wish to inherit (implement or extends) the class validation -> behavior in validation is not to be changed.
I just want to use the methods from validation class. Any OOP solutions?
Thanks in advance
You cant use include inside a class like that! Either include it at the beginning of the file ( my suggestion ) or use it one line before
$val = new validation();call.class_database.php:
class_validation.php: