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
$valwill not be in scope inpublic function login(). You need to define$valinside the function, or as a class property and access via$this->valin the function.