Results 1 to 3 of 3

Thread: [RESOLVED] Class constructor being ignored

  1. #1

    Thread Starter
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Resolved [RESOLVED] Class constructor being ignored

    What am I missing here, the constructor function is being completey ignored... the variables are empty and it doesn't echo the test strings.

    Code:
    	class cart
    	{
    	
    		var $item;
    		var $started;
    		var $max_qty;
    		var $symbol;
    		
    		function cart()
    		{
    			$this->started = time();
    			$this->max_qty = 0;
    			$this->symbol = "£";
    			echo "<h1>test</h1>";
    			echo "<h1>test</h1>";
    			echo "<h1>test</h1>";
    		}
    Chris

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Class constructor being ignored

    Are you using PHP 4 or 5?
    In 5 the constructor function should be named __construct() and var should be replaced with private (or public, as desired).

  3. #3

    Thread Starter
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Class constructor being ignored

    Just found it, __construct works yea it must be 5, I've no idea tbh just using an all in one for development. Cheers i'll use privates aswell.
    Chris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width