An issue on object orientation in php

Posted by rabidmachine9 on Stack Overflow See other posts from Stack Overflow or by rabidmachine9
Published on 2010-05-27T10:21:53Z Indexed on 2010/05/27 10:31 UTC
Read the original article Hit count: 152

Filed under:
|
|

Hello people, I have come up to issues while I'm trying to write some classes, here is an example: I have this class called TwitterGrub and I cant call it like that:

$c = new TwitterGrub();

$c->twitterDisplay();

here is the class itself:

<?php
class TwitterGrub{


function twitterCapture($user = 'username',$password = 'pass') {  


           $ch = curl_init("https://twitter.com/statuses/user_timeline.xml");  
           curl_setopt($ch, CURLOPT_HEADER, 1);  
           curl_setopt($ch,CURLOPT_TIMEOUT, 30);  
           curl_setopt($ch,CURLOPT_USERPWD,$user . ":" . $password);  
           curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);  
           curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);  
           curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);  
           $result=curl_exec ($ch);  
           $data = strstr($result, '<?');  

           $xml = new SimpleXMLElement($data);  

      return $xml;  

}  


function twitterDisplay($twitNum = 2){
    $xml = $this::twitterCapture(); 


    for($i= 0; $i<$twitNum; $i++){ 
    echo   "<div class= 'curvebox'>".$xml->status[$i]->text."</div>";

    }
}

}

?>

The problem is that everytime I want to change the username or password I have to jump back to class definition and that makes things not modular... and in many ways it feels wrong. So the question is what would be the proper way to chance my username and password through the objects interface and then call twitterDisplay() method with the new data?Hope that makes sense. Thanks in advance

© Stack Overflow or respective owner

Related posts about php

Related posts about oop