concept of object creator in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
global_erp_solution
Forum Commoner
Posts: 25
Joined: Sun Jul 08, 2012 6:47 am

concept of object creator in PHP

Post 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?
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: concept of object creator in PHP

Post by tr0gd0rr »

What kind of error do you want it to produce and why?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: concept of object creator in PHP

Post 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.
(#10850)
Post Reply