Page 2 of 2 First 12
  • Jump to page:
    #16
  1. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,953
    Rep Power
    4033
    Originally Posted by English Breakfast Tea
    Are these the same?
    PHP Code:
    self::$name;
    static::
    $name
    book
    ::$name 
    self::$name and book::$name are essentially the same thing. self:: is a way to write it without having to know/use the classes actual name. self:: can only be used from within the classes context (a method) whereas book:: could be used anywhere.

    static:: is slightly different as it takes inheritance into account. For example:
    PHP Code:
    <?php

    class {
        protected static 
    $name 'Original';

        public function 
    method1(){
            return 
    self::$name;
        }

        public function 
    method2(){
            return static::
    $name;
        }
    }

    class 
    extends {
        protected static 
    $name 'Overwritten';
    }

    $b = new b;
    var_dump($b->method1());

    var_dump($b->method2());
    self:: causes it to reference class a's version of $name. static:: causes it to reference class b's version since class b is what the object is an instance of.


    Originally Posted by English Breakfast Tea
    One other thing I like to learn is to deal with errors when chaining methods. Previously we had discussed exceptions but now seems to be the proper way to understand them.

    Should probably stop the rest of chaining as there is not any right values returned from a method.
    When you throw an exception then PHP will jump to the nearest matching catch block (or emit a fatal error if none). Any subsequent chain'ed calls will never take place.
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  2. #17
  3. Mad Scientist
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2007
    Location
    North Yorkshire, UK
    Posts
    3,661
    Rep Power
    4123
    If you look at the database classes I gave you ages ago you'll see that chaining is used quite a bit by always returning $this.

    You'll also notice that the class is a singleton, so never creates any more new instances

    You'll also see that where chaining is used, values are 'returned by reference',

    When you say

    there is not any right values returned from a method.
    what do you mean by this?

    The code you posted behaves exactly as I expect it to. Myself, and many others here, could have told you what the output would have been without needing to execute the code. The 'logic' you have is pretty simple and easy to understand. I think you're over complicating things in your own mind - are you confused by the output?

    When you access the what() method you are calling the method on different objects, because the previous different methods returns different objects

    add in a constructor and in the constructor call debug_print_backtrace()
    I said I didn't like ORM!!! <?php $this->model->update($this->request->resources[0])->set($this->request->getData())->getData('count'); ?>

    PDO vs mysql_* functions: Find a Migration Guide Here

    [ Xeneco - T'interweb Development ] - [ Are you a Help Vampire? ] - [ Read The manual! ] - [ W3 methods - GET, POST, etc ] - [ Web Design Hell ]
  4. #18
  5. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,672
    Rep Power
    171
    Originally Posted by Northie
    When you say "there is not any right values returned from a method".
    what do you mean by this?
    If the function fails for any reason. ANY type of error (database connection fail, synthax error,,,,) anything that stops the function from returning the object.

    In other words, I wanna learn the right way to design these try and catch Exceptions. There seems to be a lot of different opinions on them.
    PHP Code:
            try {        
                if(
    $this->conn != null) {
                    try {
                        
    $this->SQL $this->conn->prepare($sql);                    
                    } catch( 
    PDOExecption $e ) {
                        echo 
    $e->getMessage();
                        die();
                    }
                } else {
                    throw new 
    Exception('SQL Execution failed - Connection Closed');
                }
            } catch(
    Exception $e ) {
                echo 
    $e->getMessage();
                die();
            } 
    Jacques and Requnix mentioned a few good thingshere.
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo