Shoutbox

[PHP] Quick Dumb Question: Classes - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: [PHP] Quick Dumb Question: Classes (/showthread.php?tid=67921)

[PHP] Quick Dumb Question: Classes by L. Coyote on 11-01-2006 at 05:41 AM

Well, I'm programming again! (Yay, me!) But I'm so out-dated with everything, that I'm wondering about something...

Seeing as I can't test this until I finish more of it, I can only hope it'll work someday... So, the question is rather simple and I feel quite dumb to be asking this...

Suppose I have this:

code:
<?
class Something {

   function Something($sth, $blah) {

       if($blah == false) {

       $this->Something(functionToMakeSth(), true);

       }

   echo $this->property1;

   }

}
?>

Can I actually call the constructor again from inside the constructor? Will the changes reflect on $this later on?

For now, I'm leaving it that way until I can actually run the script. But it'd be nice to know if I'm doing it right, because I might need to do something similar in other classes. :wave:
RE: [PHP] Quick Dumb Question: Classes by WDZ on 11-01-2006 at 05:52 AM

Why don't you just make a little test script? That's what I do... :p

code:
<?php

class Something {
    var $property1 = 'property';
    function Something($sth, $blah) {
        if($blah == false) {
            $this->Something('test', true);
        }
        echo $this->property1;
        $this->property1 .= '2';
    }
}

$sth = new Something('test', false);
echo $sth->property1;

?>
That echoes "propertyproperty2property22" so I guess it works. :)
RE: [PHP] Quick Dumb Question: Classes by L. Coyote on 11-01-2006 at 06:13 AM

*sniff* WDZ!

quote:
Originally posted by WDZ
Why don't you just make a little test script? That's what I do... (Smilie)
Yeah, just great. I didn't even think about it. I was so worried about the fact that it's part of something big that I didn't think about putting that small piece into a test file. :P


It works great, WDZ. :bow: Thanks!