Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Senior Member hagen's Avatar
    Join Date
    Aug 2005
    Posts
    408
    Member #
    10882
    Liked
    1 times

    OO PHP - debugging practice example

    Hi I am very new to OO PHP so be gentle with me but I am trying to pass a property for debugging...

    I'm calling 2 methods...

    page_actions - which sets up some stuff....
    assemble_page -which outputs the html...

    there is some debug information from page_actions I want to communicate...

    outputs is -

    ths is an html page
    start.__construct



    i want

    this is an html page
    start.page_actions
    start.__construct





    PHP Code:

      
    class Main {   

       public 
    $output;              

      function 
    __construct(){
        
    $pass = new Pass();
        
    $this->page_actions();
        
    $this->output .= $this->assemble_page();
        
    $pass->debug .= 'start.__construct''<br />';
        
    $this->output .= $pass->debug;

      }


      function 
    page_actions () {

        
    $pass = new Pass();
       
    $pass->debug .= 'start.page_actions''<br />';

      } 


    function 
    assemble_page () { 

      return 
    'ths is an html page<br />';
     } 


    //end class declaration...





    class Pass {  

      public 
    $debug;              

    }


    $main = new Main();
    echo 
    $main->output
    Hagen Rose: hagen(at)jxwd(dot)co(dot)uk
    JX Web Development, Bournemouth, Dorset...JXWD.co.uk

  2.  

  3. #2
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    You're creating a new instance of Pass in page_actions(), so it is basically not doing anything. Add an argument for $pass from the constructor to be passed into page_actions instead.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  4. #3
    Senior Member hagen's Avatar
    Join Date
    Aug 2005
    Posts
    408
    Member #
    10882
    Liked
    1 times
    Thank You, I wasn't sure how the properties of a new instance of an object related to the others this answers it... IE totally unrelated?... I have a big pile of code to update so needed to get it right before I start messing it all up so very appreciated...

    output now:

    this is an html page

    start.page_actions
    start.__construct



    PHP Code:
    class Main {
        
      public 
    $output;              




      function 
    __construct(){


       
    $pass = new Pass();

       
    $this->page_actions($pass);
          
       
    $this->output .= $this->assemble_page();

       
    $pass->debug .= 'start.__construct''<br />';

       
    $this->output .= $pass->debug;

      }






      function 
    page_actions ($pass) {
        
        
    $pass->debug .= 'start.page_actions''<br />';


      }
     
      
      function 
    assemble_page () {
          
          return 
    'this is an html page<br />';
          
     }
     


    //end class declaration...



    class Pass {
        
      public 
    $debug;              


    //end class declaration...


    $main = new Main();

    echo 
    $main->output
    Hagen Rose: hagen(at)jxwd(dot)co(dot)uk
    JX Web Development, Bournemouth, Dorset...JXWD.co.uk

  5. #4
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    PHP does have some odd scoping rules, but in any language, if you create a new instance of a class, it will be different from any others. Even if you create the new instance using the same variable name in the same scope, it's a different object.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:33 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com