We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,007 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Why is a class instantiated when the class file is referenced.

Working with some OOP, I had an error that I have now traced to inistantiation of a class when the file in which the class is contained is included in any other file. Is this the default/normal behaviour of php, and how do I get myself out of this? I want to create an instance of the class at my own time.
classfile.php

<?php
Class Bibiana{
      Function __Construct(){
      print "I love you \n";
      }

Class Wed{
      Function __Construct(){
      print "And I want to marry you \n";
      print "\t Yours \n";
      print "\t Onang'o \n";
      }
#...
?>

Index.php

#include 'classfile.class.php';

Output of index.php

I love you
And I want to marry you
Onang'o
Yours
1
Contributor
1
Reply
1 Hour
Discussion Span
2 Years Ago
Last Updated
2
Views
Question
Answered
Brianbc
Light Poster
35 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

With a little bit of growing up, I have found the error in one of my scripts. The code in classfile.php is rather long, and I happened to have created an instance of Bibiana at the end of the file.

Brianbc
Light Poster
35 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Self-Answered as of 2 Years Ago

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0616 seconds using 2.74MB