PHP: Prevent chained method from returning?
        Posted  
        
            by 
                Industrial
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Industrial
        
        
        
        Published on 2011-02-22T15:15:31Z
        Indexed on 
            2011/02/22
            15:25 UTC
        
        
        Read the original article
        Hit count: 309
        
Hi,
I am having some headaches regarding method chaining for a quite simple PHP class that returns a value, which sometimes need to go through a decryption process:
$dataset = new Datacontainer;
$key = $dataset->get('key');
$key2 = $dataset->get('key')->decrypt();
The get method is where the return lives. So the call to the decrypt method on the second row isn't going to work in its current state.
Can I do something to setup the get method to return only when nothing is chained to it, or what would be the best way to re-factor this code?
© Stack Overflow or respective owner