Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

obcast

PHP7 only. It allows to cast an object to boolean by implementing new internal interface Boolable

Example

class Container implements Boolable {
    public $data = [];
    public function __toBoolean() 
    {
        return count($this->data) > 0;
    }
};

$obj = new Container();

var_dump((bool) $obj);
echo $obj ? "Not empty!\n" : "Empty!\n";

$obj->data = [1];

var_dump((bool) $obj);
echo $obj ? "Not Empty!\n" : "Empty!\n";

Output

bool(false)
Empty!
bool(true)
Not empty!

About

It allows to cast an object to boolean

Resources

Stars

14 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages