How this works ????

Started on the old forum in April 2015 · view the original in the archive · old links redirect here

1 reply · 99 views · started 11 years ago · 1 min read

2 participants
DiL Developer · 142 posts #1

Hello CT,

i have a question.....

i have write a simple class with 2 function which is here

CLASS db{

    public function select(){
        $arg = func_get_args();
        if(empty($arg)):
            $selectClust = "*";
        else:
            $selectClust = implode(',',$arg);
        endif;
        
    return "SELECT ".$selectClust;
    }
    
    public function from(nsqlQuery $e){
        $arg = func_get_args();
        return "FROM ".rtrim(implode(' ',$arg));
    }

}

and wanna use these function as

<?php

db::select()->from('table');

?>

but it is showing me error...

what should i do in my class/functions so i can use it as i want...

plz help me... thanks is advance...

Ghost Senior · 366 posts #2

try using the class like this:

CLASS db{

    public static function select(){
        $arg = func_get_args();
        if(empty($arg)):
            $selectClust = "*";
        else:
            $selectClust = implode(',',$arg);
        endif;
        
    return "SELECT ".$selectClust;
    }
    
    public static function from(nsqlQuery $e){
        $arg = func_get_args();
        return "FROM ".rtrim(implode(' ',$arg));
    }

}  

then this:

<?php

db::select()->from('table');

?>

should work correctly.

to use a class like db::somthing you need to either...

  1. make the class static (like i have here)
  2. or you need to make a constructor thats calls a function inside the class, that will make the class a single call each time its called.
👍 2
Share
<?php include ('Ghost'); if ($Post == true) { echo ' ![](http://destrukt.dk/ico/phpdeveloper.jpg) alt='coding-talk.com!!' />'; echo 'Sharing Is Caring!'; } else { echo ' ![](http://img98.imageshack.us/img98/6476/av3ro4.jpg) alt='the username GHOST has been comprimised!' />'; echo 'OMG SOMEBODY HELP ME!!'; } ?>

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close