Why does this PHP code output anything at all??

Discussion in 'PHP' started by carlos123, Oct 5, 2009.

  1. #1
    The following code echo's (outputs) "some value" to the screen. I don't get it. Why does it output anything at all since I don't call the show() method at all?

    
    <?php
    class some
    {
    	static $value = "some value";
    
    	function __construct()
    	{
    		$this->value =	"another value";
    	}
    
    	function getStyle()
    	{
    		return $this->value;
    	}
    }
    
    class webPage extends some {
    
    	public function show()
    	{
    		echo parent::$value."<br>";
    	}
    }
    
    $page = new webPage();
    //$page->show();
    ?>
    
    Code (markup):
    What I am trying to do is access properties (variables) of the some class inside the webPage class in such a way that I can readily identify them as coming from a parent class on a cursory look through the code inside the webPage class.

    I would like the code to run at least several versions back from 5.3.0 if possible.

    I thought using the parent:: operator might do it but as you can see it's acting very strange.

    Anybody got any ideas or suggestions?

    Thanks.

    Carlos
     
    carlos123, Oct 5, 2009 IP
  2. nigelr

    nigelr Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    sounds like that change to comment out show didn't get uploaded to your server correctly - still using the version you had prior to you making that change
     
    nigelr, Oct 5, 2009 IP
  3. carlos123

    carlos123 Peon

    Messages:
    58
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks so much for getting back to me. It was my fault entirely!

    As a result of staring at PHP code all day without hardly taking a break I had accidentally been running the code from another similarly named file to the code above. I kept changing the code above and couldn't for the life of me figure out how it was producing any output at all LOL.

    Quite silly but it's happened before.

    Thanks again.

    Carlos
     
    carlos123, Oct 5, 2009 IP
  4. lmao

    lmao Guest

    Messages:
    93
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    it happened to me also LOL
     
    lmao, Oct 8, 2009 IP