Jump to content


  • Posts

  • Joined

  • Last visited


Everything posted by TomTees

  1. Okay. I may have read a few, but I'll go back and re-read all of them **SIDE NOTE: See, this is what is soooo frustrating about trying to learn OOP. "I" know very little. And a lot of "experts" don't know a whole lot more!! So who am I to believe?! There is so much misinformation out there on the Internet that it is mind-boggling, and a person really has to be careful to not just trust the masses, lest they become part of the (uneducated) masses. In the final analysis, I just try to ask enough supposed "experts" to get a decent feel for what approaches and theories seem to make sense, but Getters/Setters is a prime example of not knowing who to believe... It's not scary. It's written very plainly. The biggest hurdle is that the examples are written in C++ and Smalltalk. Their syntax is similar enough to PHP's to make it a non-issue. Okay. TomTees
  2. And someone before you said it *would* work! What's a newb to do?! So I tried it out and looks like you were right and the other person was wrong! TomTees
  3. Fatal error: Call to private FormHandler4::__construct() from invalid context in /Users/user1/Documents/DEV/++htdocs/Test2/results.php on line 6 Yep! You were right about using "private" for my constructor!! TomTees
  4. So if I have this class... class FormHandler4 { private $myFormArray = array(); private function __construct($input = false){ if(is_array($input)){ $this->myFormArray = $input; } } } And I instantiate it using this... $objFormHandler4 = new FormHandler4($_POST); You are saying it won't work (i.e. instantiate a new object)?? It is on my "To-Do List", but I'm not far enough long with OOP to understand what a book of that magnitude probably says... (I hear it is s-c-a-r-y?!) TomTees
  5. You're not planning on making all your classes static or Singletons, are you? Nope. Not at all. But based on what you said, it sounds like I can make all constructors "private"... TomTees
  6. From what was described before, you could call the __Constructor repeatedly even if you hadn't instantiated yet. (Maybe I misunderstood?!) Yeah, I think you misunderstood. Calling the constructor IS instantiating an object. Whenever the word 'new' is written an object is being instantiated. Now, you don't need to DEFINE a constructor. If you don't define one, PHP will simply invoke the default constructor, which doesn't do anything but tell PHP "Hey, this is an object." You CAN make a constructor private. This is used when you want to deny public/multiple instantiation. It's a critical part of the Singleton pattern and other static classes (Factories). Now that makes more sense!! I understand what you said above and that seems more consistent with my concerns. So "private" for my constructors it is! Thanks, TomTees
  7. Maybe too strong of a term, but it could be enacted by another developer when it shouldn't be. From what was described before, you could call the __Constructor repeatedly even if you hadn't instantiated yet. (Maybe I misunderstood?!) Someone earlier said you could make it "private" but I guess that isn't so. I'm just averse to "public" anything if it doesn't need to be set as such! TomTees
  8. If it is left "Public", can anyone tamper with it? TomTees It can be executed (and will instantiate the object), and it can also be overridden. So you just have to live with it being "public" and hope your constructor doesn't get hacked, huh? :-\ TomTees
  9. If it is left "Public", can anyone tamper with it? TomTees
  10. BTW, is it... class FormHandler3 { or class FormHandler3{ or doesn't the extra space matter? What about on functions? TomTees
  11. > private $_data = array(); Why do you use the format $_data ?? > public function __construct($input = false) Can this be "private"? TomTees
  12. How would I assign the $_POST array to an internal array in my Constructor? Why don't you like doing it in the Constructor? TomTees P.S. What is wrong with PHPFreaks the last few weeks? The website keeps showing errors when I access it?!
  13. If I were to assign the $_POST array to another internal array in my object would that be more multi-functional? TomTees
  14. Except using Getters/Setters is a bad idea. http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html That is what I'm trying to learn now. How to create and pass objects to other objects. (I believe that is the "proper" OOP way to do things?!) TomTees
  15. That simple, huh?! Actually I'm the one that had things mixed up! So, some follow-up questions... 1.) If this was a real app, how would I protect the password? 2.) How do I "return" both the email and password from the object (e.g. I want to echo them)? 3.) Can I use different names for the parameters in my constructor or must they match the Instance Variables? public function __construct($email, $password){ $this->email = $email; $this->password = $password; } 4.) If I pass this object to another object will I then be able to access the email and password? TomTees
  16. I'm practicing my OOP skills and want to pass $_POST values to an Object's Instance Variables when a form is submitted. This is what I have so far... index.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> </head> <body> <!-- Registration Form --> <form method="post" action="results.php"> <!-- Registration Fields --> <div> <label for="email">E-mail:</label> <input type="text" name="email" class="txt" id="email" /> </div> <div> <label for="password">Password:</label> <input type="password" name="password" class="txt" id="password" /> </div> <div> <input type="submit" name="btnSubmit" value="Register" class="btn" id="btnSubmit" /> </div> </form> </body> </html> results.php <?php include ('classes/FormHandler.class.php'); ?> FormHandler.class.php <?php class HandleForm { // Define Variables. private $email; private $password; public function __construct($email, $password){ $this->email = $email; $this->password = $password; } } ?> I'm a little stuck on how I initialize the Instance Variables in the Constructor?! TomTees
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.