Page 1 of 1

concept of object creator in PHP

Posted: Sun Jul 08, 2012 7:04 am
by global_erp_solution

Code: Select all

interface Nameable{

    function getName();

}

Code: Select all

class TheClass implements Nameable{

    private function __construct(){}

    public static function makeNew(){

        return self::makeObject(new TheClass());

    }

    private static function makeObject(Nameable $nameable){

        return $nameable;

    }

    function getName(){return 'Jennifer';}

    function getPhone(){return '123456;}

}

Code: Select all

$class=TheClass::makeNew();
echo $class->getPhone();
This code works just fine, while I want it to produce error. the intellisense worked fine, the getPhone() didn't get displayed during code complete. But if I force writting it, and run it via browser, "123456" still got printed with no error. How do I avoid this?

Re: concept of object creator in PHP

Posted: Mon Jul 09, 2012 2:24 pm
by tr0gd0rr
What kind of error do you want it to produce and why?

Re: concept of object creator in PHP

Posted: Mon Jul 09, 2012 3:40 pm
by Christopher
Just create objects normally and don't use weird object creator classes. It will be clearer in your editor and it will be better code.