|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#26 |
|
Messages: n/a
Hébergeur: |
On Jan 30, 2008 10:53 AM, Stut <stuttle@gmail.com> wrote:
> Nathan Nobbe wrote: > I never said I wasn't creating > an instance in the example I posted. > then what exactly did you mean by this? Actually no, I mean I would *just* use a static method. If there is no reason to instantiate an object, why would you? -nathan |
|
|
|
#27 |
|
Messages: n/a
Hébergeur: |
Nathan Nobbe wrote:
> On Jan 30, 2008 10:53 AM, Stut <stuttle@gmail.com > <mailto:stuttle@gmail.com>> wrote: > > Nathan Nobbe wrote: > I never said I wasn't creating > an instance in the example I posted. > > > then what exactly did you mean by this? > > Actually no, I mean I would *just* use a static method. If there is no > reason to instantiate an object, why would you? I meant "I would *just* use a static method". Calling a static method does not create an instance of the class. My comments usually follow the rule of Ronseal. What do you think I meant by it? -Stut -- http://stut.net/ |
|
|
|
#28 |
|
Messages: n/a
Hébergeur: |
Stut wrote:
> Nathan Nobbe wrote: >> On Jan 30, 2008 10:53 AM, Stut <stuttle@gmail.com >> <mailto:stuttle@gmail.com>> wrote: >> >> Nathan Nobbe wrote: >> I never said I wasn't creating >> an instance in the example I posted. >> >> >> then what exactly did you mean by this? >> >> Actually no, I mean I would *just* use a static method. If there is no >> reason to instantiate an object, why would you? > > I meant "I would *just* use a static method". Calling a static method > does not create an instance of the class. My comments usually follow the > rule of Ronseal. > > What do you think I meant by it? > > -Stut > From your previous email -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare |
|
|
|
#29 |
|
Messages: n/a
Hébergeur: |
On Jan 30, 2008 11:21 AM, Stut <stuttle@gmail.com> wrote:
> Calling a static method > does not create an instance of the class. there you go again; calling a static method does create an instance of the class if you call new inside of it :P -nathan |
|
|
|
#30 |
|
Messages: n/a
Hébergeur: |
Stut wrote:
> Nathan Nobbe wrote: >> On Jan 30, 2008 10:53 AM, Stut <stuttle@gmail.com >> <mailto:stuttle@gmail.com>> wrote: >> >> Nathan Nobbe wrote: >> I never said I wasn't creating >> an instance in the example I posted. >> >> >> then what exactly did you mean by this? >> >> Actually no, I mean I would *just* use a static method. If there is no >> reason to instantiate an object, why would you? > > I meant "I would *just* use a static method". Calling a static method > does not create an instance of the class. My comments usually follow the > rule of Ronseal. > > What do you think I meant by it? > > -Stut > From your previous email <?php class Test { public static function doSomething() { $o = new Test(); The above line IS creating a instance of the class Test Now with proper garbage collection, it should be wiped out when you are done using the static doSomething() method. $o->_doSomething(); You could always include this to remove the instance of class Test unset($o); } protected function _doSomething() { // I'm assuming this method is fairly complex, and involves // more than just this method, otherwise there is no point // in creating an instance of the class, just use a static // method. } } Test::doSomething(); ?> -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare |
|
|
|
#31 |
|
Messages: n/a
Hébergeur: |
Nathan Nobbe wrote:
> On Jan 30, 2008 11:21 AM, Stut <stuttle@gmail.com > <mailto:stuttle@gmail.com>> wrote: > > Calling a static method > does not create an instance of the class. > > > there you go again; calling a static method does create an instance of > the class if you call new inside of it :P FFS, are you just trolling? Note that I actually wrote "*just* a static method", and I stated quite clearly that it was what I would do and that the code I posted was providing what the OP wanted. If you can't see the separation then I'm done with trying to convince you. -Stut -- http://stut.net/ |
|
|
|
#32 |
|
Messages: n/a
Hébergeur: |
Jim Lucas wrote:
> Stut wrote: >> Nathan Nobbe wrote: >>> On Jan 30, 2008 10:53 AM, Stut <stuttle@gmail.com >>> <mailto:stuttle@gmail.com>> wrote: >>> >>> Nathan Nobbe wrote: >>> I never said I wasn't creating >>> an instance in the example I posted. >>> >>> >>> then what exactly did you mean by this? >>> >>> Actually no, I mean I would *just* use a static method. If there is no >>> reason to instantiate an object, why would you? >> >> I meant "I would *just* use a static method". Calling a static method >> does not create an instance of the class. My comments usually follow >> the rule of Ronseal. >> >> What do you think I meant by it? >> >> -Stut >> > > From your previous email > > > <?php > class Test { > public static function doSomething() { > $o = new Test(); > > The above line IS creating a instance of the class Test > > Now with proper garbage collection, it should be wiped out when you are > done using the static doSomething() method. > > $o->_doSomething(); > > You could always include this to remove the instance of class Test > > unset($o); > > > } > > protected function _doSomething() { > // I'm assuming this method is fairly complex, and involves > // more than just this method, otherwise there is no point > // in creating an instance of the class, just use a static > // method. > } > } > Test::doSomething(); > ?> "I would *just* use a static method" *just* *just* *just* *just* *just* *just* *just* *just* *just* No instance. None. Grrr. FFS. -Stut -- http://stut.net/ |
|
|
|
#33 |
|
Messages: n/a
Hébergeur: |
On Jan 30, 2008 11:31 AM, Stut <stuttle@gmail.com> wrote:
> > "I would *just* use a static method" > > *just* *just* *just* *just* *just* *just* *just* *just* *just* > > No instance. None. Grrr. here is a mod of the code you posted w/ a var_dump() of the local variable $o; <?php class Test { public static function doSomething() { $o = new Test(); var_dump($o); $o->_doSomething(); } protected function _doSomething() { // I'm assuming this method is fairly complex, and involves // more than just this method, otherwise there is no point // in creating an instance of the class, just use a static // method. } } Test::doSomething(); ?> nathan@gentooss ~/ticketsDbCode $ php testCode.php object(Test)#1 (0) { } clearly in the act of *just* using a static method, you *just* created an instance of class Test ![]() -nathan |
|
|
|
#34 |
|
Messages: n/a
Hébergeur: |
Nathan Nobbe wrote:
> On Jan 30, 2008 11:31 AM, Stut <stuttle@gmail.com > <mailto:stuttle@gmail.com>> wrote: > > > "I would *just* use a static method" > > *just* *just* *just* *just* *just* *just* *just* *just* *just* > > No instance. None. Grrr. > > > here is a mod of the code you posted w/ a var_dump() of the > local variable $o; > > <?php > class Test { > public static function doSomething() { > $o = new Test(); > var_dump($o); > $o->_doSomething(); > } > > protected function _doSomething() { > // I'm assuming this method is fairly complex, and involves > // more than just this method, otherwise there is no point > // in creating an instance of the class, just use a static > // method. > } > } > Test::doSomething(); > ?> > > nathan@gentooss ~/ticketsDbCode $ php testCode.php > object(Test)#1 (0) { > } > > > clearly in the act of *just* using a static method, you *just* > created an instance of class Test ![]() Ok, I'm going to have to assume you really are as stupid as you seem. If I need to provide an example to demonstrate what I meant I will, but I feel I made it quite clear that my comment regarding what *I* would do did not in any way relate to the code example I had provided above. The example I provided was fulfilling the OP's requirements. This is what *I* would do... <?php class Test { public static function doSomething() { // I'm assuming this method is fairly complex, and involves // more than just this method, otherwise there is no point // in creating an instance of the class, just use a static // method. // ^^^^ See this comment here, this was taken from the // non-static method in the example I posted. This is what // I meant when I say "just use a static method". } } Test::doSomething(); ?> Look ma, no instance. FYI I'm not at all new to OOP, in general or in PHP, so I am well aware that the example I originally posted created an instance of the class. -Stut -- http://stut.net/ |
|
|
|
#35 |
|
Messages: n/a
Hébergeur: |
Stut wrote:
> Nathan Nobbe wrote: >> On Jan 30, 2008 11:31 AM, Stut <stuttle@gmail.com >> <mailto:stuttle@gmail.com>> wrote: >> >> >> "I would *just* use a static method" >> >> *just* *just* *just* *just* *just* *just* *just* *just* *just* >> >> No instance. None. Grrr. >> >> >> here is a mod of the code you posted w/ a var_dump() of the >> local variable $o; >> >> <?php >> class Test { >> public static function doSomething() { >> $o = new Test(); >> var_dump($o); >> $o->_doSomething(); >> } >> >> protected function _doSomething() { >> // I'm assuming this method is fairly complex, and involves >> // more than just this method, otherwise there is no point >> // in creating an instance of the class, just use a static >> // method. >> } >> } >> Test::doSomething(); >> ?> >> >> nathan@gentooss ~/ticketsDbCode $ php testCode.php >> object(Test)#1 (0) { >> } >> >> >> clearly in the act of *just* using a static method, you *just* >> created an instance of class Test ![]() > > Ok, I'm going to have to assume you really are as stupid as you seem. If > I need to provide an example to demonstrate what I meant I will, but I > feel I made it quite clear that my comment regarding what *I* would do > did not in any way relate to the code example I had provided above. The > example I provided was fulfilling the OP's requirements. > > This is what *I* would do... > > <?php > class Test { > public static function doSomething() { > // I'm assuming this method is fairly complex, and involves > // more than just this method, otherwise there is no point > // in creating an instance of the class, just use a static > // method. > > // ^^^^ See this comment here, this was taken from the > // non-static method in the example I posted. This is what > // I meant when I say "just use a static method". > } > } > Test::doSomething(); > ?> > > Look ma, no instance. Now this is clear. But to point out in the code I quoted, you said that you were going to only use the static method, but you were calling the static method that created an instance of the Test class and then calling the non-static method from the instance of the Test class. Your previous example was not showing us what you were saying. To me it looked like you were confused about how you were calling/creating things. -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare |
|
|
|
#36 |
|
Messages: n/a
Hébergeur: |
On Jan 30, 2008 11:58 AM, Stut <stuttle@gmail.com> wrote:
> Ok, I'm going to have to assume you really are as stupid as you seem. If > I need to provide an example to demonstrate what I meant I will, but I > feel I made it quite clear that my comment regarding what *I* would do > did not in any way relate to the code example I had provided above. The > example I provided was fulfilling the OP's requirements. > > This is what *I* would do... > > <?php > class Test { > public static function doSomething() { > // I'm assuming this method is fairly complex, and involves > // more than just this method, otherwise there is no point > // in creating an instance of the class, just use a static > // method. > > // ^^^^ See this comment here, this was taken from the > // non-static method in the example I posted. This is what > // I meant when I say "just use a static method". > } > } > Test::doSomething(); > ?> > > Look ma, no instance. > well, at least its clear now, what you meant. > FYI I'm not at all new to OOP, in general or in PHP, so I am well aware > that the example I originally posted created an instance of the class. glad to hear it; no hard feelings i hope.. -nathan |
|
|
|
#37 |
|
Messages: n/a
Hébergeur: |
Jim Lucas wrote:
> Stut wrote: >> Nathan Nobbe wrote: >>> On Jan 30, 2008 11:31 AM, Stut <stuttle@gmail.com >>> <mailto:stuttle@gmail.com>> wrote: >>> >>> >>> "I would *just* use a static method" >>> >>> *just* *just* *just* *just* *just* *just* *just* *just* *just* >>> >>> No instance. None. Grrr. >>> >>> >>> here is a mod of the code you posted w/ a var_dump() of the >>> local variable $o; >>> >>> <?php >>> class Test { >>> public static function doSomething() { >>> $o = new Test(); >>> var_dump($o); >>> $o->_doSomething(); >>> } >>> >>> protected function _doSomething() { >>> // I'm assuming this method is fairly complex, and involves >>> // more than just this method, otherwise there is no point >>> // in creating an instance of the class, just use a static >>> // method. >>> } >>> } >>> Test::doSomething(); >>> ?> >>> >>> nathan@gentooss ~/ticketsDbCode $ php testCode.php >>> object(Test)#1 (0) { >>> } >>> >>> >>> clearly in the act of *just* using a static method, you *just* >>> created an instance of class Test ![]() >> >> Ok, I'm going to have to assume you really are as stupid as you seem. >> If I need to provide an example to demonstrate what I meant I will, >> but I feel I made it quite clear that my comment regarding what *I* >> would do did not in any way relate to the code example I had provided >> above. The example I provided was fulfilling the OP's requirements. >> >> This is what *I* would do... >> >> <?php >> class Test { >> public static function doSomething() { >> // I'm assuming this method is fairly complex, and involves >> // more than just this method, otherwise there is no point >> // in creating an instance of the class, just use a static >> // method. >> >> // ^^^^ See this comment here, this was taken from the >> // non-static method in the example I posted. This is what >> // I meant when I say "just use a static method". >> } >> } >> Test::doSomething(); >> ?> >> >> Look ma, no instance. > > Now this is clear. Glad to hear it. > But to point out in the code I quoted, you said that you were going to > only use the static method, but you were calling the static method that > created an instance of the Test class and then calling the non-static > method from the instance of the Test class. I thought the comment in that static method explained that I didn't see the point in creating the instance. I thought it was pretty clear, but clearly not. > Your previous example was not showing us what you were saying. To me it > looked like you were confused about how you were calling/creating things. I was never confused! ![]() -Stut -- http://stut.net/ |
|
|
|
#38 |
|
Messages: n/a
Hébergeur: |
Nathan Nobbe wrote:
> On Jan 30, 2008 11:58 AM, Stut <stuttle@gmail.com > <mailto:stuttle@gmail.com>> wrote: > > Ok, I'm going to have to assume you really are as stupid as you seem. If > I need to provide an example to demonstrate what I meant I will, but I > feel I made it quite clear that my comment regarding what *I* would do > did not in any way relate to the code example I had provided above. The > example I provided was fulfilling the OP's requirements. > > This is what *I* would do... > > <?php > class Test { > public static function doSomething() { > // I'm assuming this method is fairly complex, and involves > // more than just this method, otherwise there is no point > // in creating an instance of the class, just use a static > // method. > > // ^^^^ See this comment here, this was taken from the > // non-static method in the example I posted. This is what > // I meant when I say "just use a static method". > } > } > Test::doSomething(); > ?> > > Look ma, no instance. > > > well, at least its clear now, what you meant. > > > FYI I'm not at all new to OOP, in general or in PHP, so I am well aware > that the example I originally posted created an instance of the class. > > > glad to hear it; no hard feelings i hope.. Indeed. Now, the place where you sleep... is it guarded? ![]() -Stut -- http://stut.net/ |
|
|
|
#39 |
|
Messages: n/a
Hébergeur: |
>
> Indeed. Now, the place where you sleep... is it guarded? well it is, but.. i probly misunderstood some implication in the directions of my virtual fortress and therefore, probly not as well a i suspect ![]() -nathan |
|
|
|
#40 |
|
Messages: n/a
Hébergeur: |
On Wed, January 30, 2008 9:53 am, Stut wrote:
> The "forcing it out of scope" was the crux of my point. However, if > Jochem is right then it's kinda pointless with the current > implementation of the GC, but may become relevant in the new GC. I dunno about the OOP instances getting GC'ed, but PHP *definitely* reclaims memory from arrays and strings as they go out of scope, usually. You can work at something complicated enough to confuse it that it won't reclaim it, but you have to work at it to get there. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? |
|
|
|
#41 |
|
Messages: n/a
Hébergeur: |
> I dunno about the OOP instances getting GC'ed, but PHP *definitely* > reclaims memory from arrays and strings as they go out of scope, > usually. Does anyone else find that funny? ![]() It definitely does it ... usually ![]() -- Postgresql & php tutorials http://www.designmagick.com/ |
|
|
|
#42 |
|
Messages: n/a
Hébergeur: |
I believe the constructor returns the object created, with no chance
in userland code of altering that fact, over-riding the return value, or any other jiggery-pokery to that effect. New causes the constructor to be called in the first place, and that's about it. The assignment to a variable is done by the assignment operator "=" and is not required if you don't have any need to actually keep the object around in a variable. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? |
|
|
|
#43 |
|
Messages: n/a
Hébergeur: |
On Wed, January 30, 2008 6:19 pm, Chris wrote: > >> I dunno about the OOP instances getting GC'ed, but PHP *definitely* >> reclaims memory from arrays and strings as they go out of scope, >> usually. > > Does anyone else find that funny? ![]() > > It definitely does it ... usually ![]() Ah well. It definitely does it when it can, but you can confuse it with enough circular references and large enough data structures that it ends up with a giant mess of data it can't GC, because it's just not THAT smart. There are improvements coming in this area, I think, in PHP 6, if I remember the posts to internals correctly. -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? |
|
|
|
#44 |
|
Messages: n/a
Hébergeur: |
Richard Lynch wrote:
> > On Wed, January 30, 2008 6:19 pm, Chris wrote: >>> I dunno about the OOP instances getting GC'ed, but PHP *definitely* >>> reclaims memory from arrays and strings as they go out of scope, >>> usually. >> Does anyone else find that funny? ![]() >> >> It definitely does it ... usually ![]() > > Ah well. I was just picking on the phrasing, nothing else ![]() > It definitely does it when it can, but you can confuse it with enough > circular references and large enough data structures that it ends up > with a giant mess of data it can't GC, because it's just not THAT > smart. Yep, they suck pretty hard and can be pretty hard to unravel at times but that's another topic altogether. > There are improvements coming in this area, I think, in PHP 6, if I > remember the posts to internals correctly. Awesome ![]() -- Postgresql & php tutorials http://www.designmagick.com/ |
|
|
|
#45 |
|
Messages: n/a
Hébergeur: |
Richard Lynch schreef:
> I believe the constructor returns the object created, with no chance > in userland code of altering that fact, over-riding the return value, > or any other jiggery-pokery to that effect. > > New causes the constructor to be called in the first place, and that's > about it. > > The assignment to a variable is done by the assignment operator "=" > and is not required if you don't have any need to actually keep the > object around in a variable. I thought that's what I said. maybe less clearly :-) > |
|
|
|
#46 |
|
Messages: n/a
Hébergeur: |
On Jan 30, 2008 4:53 PM, Jochem Maas <jochem@iamjochem.com> wrote:
> Richard Lynch schreef: > > I believe the constructor returns the object created, with no chance > > in userland code of altering that fact, over-riding the return value, > > or any other jiggery-pokery to that effect. > > > > New causes the constructor to be called in the first place, and that's > > about it. > > > > The assignment to a variable is done by the assignment operator "=" > > and is not required if you don't have any need to actually keep the > > object around in a variable. > > I thought that's what I said. maybe less clearly :-) > > > > I don't think constructors return the object: <?php class foo { private $bar; public function __construct($bar) { echo "In constructor\n"; $this->bar = $bar; } } $x = new foo("..."); var_dump($x->__construct("....")); # NULL ?> -- -Casey |
|
|
|
#47 |
|
Messages: n/a
Hébergeur: |
On Jan 30, 2008 11:29 PM, Casey <heavyccasey@gmail.com> wrote:
> I don't think constructors return the object: im starting to think this as well. what for example happens when there is not __construct() method ? class Test { private $blah = ''; } here $blah is part of a new instance, before __construct() would get called, if it was defined. this makes me think php creates an internal object, and optionally lets __construct() alter it if defined. i think somebody may have already said that, but i didnt feel like wading through the previous posts for it.. -nathan |
|
![]() |
| Outils de la discussion | |
|
|