I was wondering why my php program is not returning the correct TRUE FALSE value when the class is included elsewhere
it goes something like this
source: signup.php
class signup
{
function buildProfile()
{
if($logic){
$this->success = TRUE;
}else{
$this->success = FALSE;
}
}
function __construct()
{
$this->success = NULL;
$this->buildProfile
return $this->success;
}
}
and elsewhere I do
include('signup.php');
$signup = new signup();
if($signup){
successFunction();
}else....
but it’s not getting $signup == true, it’s getting FALSE every time
Constructors always return a new instance of the class. You cannot return any other type of value from a constructor. A better way to structure your code would be something like:
Then when you construct the object you could do: