Class __construct

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

kahwooi
Forum Commoner
Posts: 25
Joined: Fri Dec 10, 2004 12:28 am

Class __construct

Post by kahwooi »

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Can I do this? I get an error, is there a better way to do it? Thank You.

Code: Select all

class test{

 	public function __construct(){
		$this->testing = new testing();
 	}

 }

 class testing{
 	public function __construct(){
 		$this->test = new test();
 	}
 }

Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
technofreak
Forum Commoner
Posts: 74
Joined: Thu Jun 01, 2006 12:30 am
Location: Chennai, India
Contact:

Post by technofreak »

What are you trying to do with that code ?
kahwooi
Forum Commoner
Posts: 25
Joined: Fri Dec 10, 2004 12:28 am

Post by kahwooi »

So that I can use the functions in testing class from test class and vice versa.

Thanks for your reply.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Code: Select all

<?php
class Test
{ 
	private $testing;
	
	public function __construct ()
	{ 
		$this->testing = new testing(); 
	} 

} 

class Testing
{
	private $test;

	public function __construct ()
	{
		$this->test = new test();
	}
}

$test = new Test;
$testing = new Testing;
?>
kahwooi
Forum Commoner
Posts: 25
Joined: Fri Dec 10, 2004 12:28 am

Post by kahwooi »

I get Internal Server Error after running Jenk's code with the following message:

The server encountered an internal error or misconfiguration and was unable to complete your request.

Thank you Jenk for helping out.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

kahwooi wrote:I get Internal Server Error after running Jenk's code with the following message:

The server encountered an internal error or misconfiguration and was unable to complete your request.

Thank you Jenk for helping out.
Sounds like Apache or PHP is not installed/configured correctly. The code is fine ;)
kahwooi
Forum Commoner
Posts: 25
Joined: Fri Dec 10, 2004 12:28 am

Post by kahwooi »

Anyone has any clue what I had done wrong with my setting?
I'm clueless!!!!
kahwooi
Forum Commoner
Posts: 25
Joined: Fri Dec 10, 2004 12:28 am

Post by kahwooi »

Is the code from Jenk working?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

I've noticed a couple typo's in my post.. though they shouldn't be the cause of your server error:

Code: Select all

<?php 
class Test 
{ 
        private $testing; 
        
        public function __construct () 
        { 
                $this->testing = new Testing(); 
        } 

} 

class Testing 
{ 
        private $test; 

        public function __construct () 
        { 
                $this->test = new Test(); 
        } 
} 

$test = new Test; 
$testing = new Testing; 
?>
kahwooi
Forum Commoner
Posts: 25
Joined: Fri Dec 10, 2004 12:28 am

Post by kahwooi »

So is apache problem or php??? Thank you Jenk!
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

either/or in all reality.

Is this hosted or local?
kahwooi
Forum Commoner
Posts: 25
Joined: Fri Dec 10, 2004 12:28 am

Post by kahwooi »

it is local, I'm using php 5.1.2 and Apache 2.0.55
kahwooi
Forum Commoner
Posts: 25
Joined: Fri Dec 10, 2004 12:28 am

Post by kahwooi »

Are you all using php 5.1.2 and Apache 2.0.55? I reinstalled the PHP and Apache, but I'm facing the same problem.
kahwooi
Forum Commoner
Posts: 25
Joined: Fri Dec 10, 2004 12:28 am

Post by kahwooi »

This is what I get from error log:

Premature end of script headers: php-cgi.exe
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

google returns the below when searching for the error message..
i couldn't get it work as well. I would receive "Today is //". This is what I did to correct the problem. 1)I'm using Win XP pro Service pack 1, PHP 5.0.3RC1, Apache 2.0.52. I did not move the "php5ts.dll" to c:\windows BUT to c:\windows\system32. 2) Go to this PHP link and follow the directions on this page http://www.php.net/manual/en/install.wi ... pache2.php 3) Next edit the index.php file you created in step 1(above)and delete the line and replace it with <?php phpinfo () ; ?> then save this file. Then open http://localhost you should have a graphical list of all your PHP info this file is much more useful then the file above. If it did not work then you need to go through the step 6 Configuring PHP5 with Apache (UP TO STEP 4 ONLY) then follow the link I have above and double check your settings again. Good Luck hope works for you. I spent 2 days trying to get this thing to work.
Post Reply