[PHP] Object Copying
As we all know, this copies an object in PHP: $obj2 = $obj1 Assuming $obj1 is an object (of a class). I want this never, ever to happen unless I want it to. All the time, I run into something where PHP made a copy of my object for X odd reason -- I pass an object to a function, I put it in an array, etc etc etc. Is there a way I can have PHP warn me if an object is copied, or put that in the class code somehow? Preferable a way to fix PHP not to copy the object, but the reference. I'd settle for a warning system though. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Specific References Incident
I have one specific incident I could use some help with too. I have the following method: function validate() { if ($this->returning) { $errors = array(); foreach ($this->children as $child) { $child->error = "Foo"; $error = $child->validate(); if ($error) { $this->errors_exist = 1; array_push ($errors, $error); } } } $this->errors = $errors; } The $this->children attribute should be an array of (references to) objects. I think somehow in the foreach ($this->children as $child) the objects are being copied, as $child->validate(); seems not to effect the original objects. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Specific References Incident
That's what I had thought too, but no: Parse error: parse error, expecting `T_VARIABLE' or `'$'' in /home/ken/Projects/kwidgets/widgets.inc on line 74 On Thursday 10 January 2002 04:51 pm, Martin Towell wrote: > does this work?? change > foreach ($this->children as $child) { > to > foreach ($this->children as &$child) { > > > -Original Message- > From: Ken Kinder [mailto:[EMAIL PROTECTED]] > Sent: Friday, January 11, 2002 10:44 AM > To: [EMAIL PROTECTED] > Subject: [PHP] Specific References Incident > > > I have one specific incident I could use some help with too. I have the > following method: > > function validate() { > if ($this->returning) { > $errors = array(); > > foreach ($this->children as $child) { > $child->error = "Foo"; > $error = $child->validate(); > if ($error) { > $this->errors_exist = 1; > array_push ($errors, $error); > } > } > } > > $this->errors = $errors; > } > > The $this->children attribute should be an array of (references to) > objects. > > I think somehow in the foreach ($this->children as $child) the objects are > being copied, as $child->validate(); seems not to effect the original > objects. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Specific References Incident
Negative. On Thursday 10 January 2002 04:54 pm, Mark wrote: > On Thu, 10 Jan 2002 16:49:45 -0700, Ken Kinder wrote: > >That's what I had thought too, but no: > > > >Parse error: parse error, expecting `T_VARIABLE' or `'$'' in > >/home/ken/Projects/kwidgets/widgets.inc on line 74 > > how about this: > foreach ($this->children as $key => $value) { > $child=&$this->children[$key]; > > >On Thursday 10 January 2002 04:51 pm, Martin Towell wrote: > >> does this work?? change > >>foreach ($this->children as $child) { > >> to > >>foreach ($this->children as &$child) { > >> > >> > >> -Original Message- > >> From: Ken Kinder [mailto:[EMAIL PROTECTED]] > >> Sent: Friday, January 11, 2002 10:44 AM > >> To: [EMAIL PROTECTED] > >> Subject: [PHP] Specific References Incident > >> > >> > >> I have one specific incident I could use some help with too. I > >>have the > >> following method: > >> > >> function validate() { > >> if ($this->returning) { > >>$errors = array(); > >> > >>foreach ($this->children as $child) { > >> $child->error = "Foo"; > >> $error = $child->validate(); > >> if ($error) { > >> $this->errors_exist = 1; > >> array_push ($errors, $error); > >> } > >>} > >> } > >> > >> $this->errors = $errors; > >> } > >> > >> The $this->children attribute should be an array of (references > > to) > > >> objects. > >> > >> I think somehow in the foreach ($this->children as $child) the > >>objects are > >> being copied, as $child->validate(); seems not to effect the > >>original > >> objects. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Second newbie question
I have a second newbie question, and I promise I really did try to find this in the docs. Is there a method that can be called when an attribute or method is called that doesn't exist? A catch-all method? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Specific References Incident
Nope. Tried that too. On Thursday 10 January 2002 05:18 pm, Rasmus Lerdorf wrote: > Use a while(list()=each()) loop. > > On Thu, 10 Jan 2002, Ken Kinder wrote: > > Negative. > > > > On Thursday 10 January 2002 04:54 pm, Mark wrote: > > > On Thu, 10 Jan 2002 16:49:45 -0700, Ken Kinder wrote: > > > >That's what I had thought too, but no: > > > > > > > >Parse error: parse error, expecting `T_VARIABLE' or `'$'' in > > > >/home/ken/Projects/kwidgets/widgets.inc on line 74 > > > > > > how about this: > > > foreach ($this->children as $key => $value) { > > > $child=&$this->children[$key]; > > > > > > >On Thursday 10 January 2002 04:51 pm, Martin Towell wrote: > > > >> does this work?? change > > > >>foreach ($this->children as $child) { > > > >> to > > > >>foreach ($this->children as &$child) { > > > >> > > > >> > > > >> -Original Message- > > > >> From: Ken Kinder [mailto:[EMAIL PROTECTED]] > > > >> Sent: Friday, January 11, 2002 10:44 AM > > > >> To: [EMAIL PROTECTED] > > > >> Subject: [PHP] Specific References Incident > > > >> > > > >> > > > >> I have one specific incident I could use some help with too. I > > > >>have the > > > >> following method: > > > >> > > > >> function validate() { > > > >> if ($this->returning) { > > > >>$errors = array(); > > > >> > > > >>foreach ($this->children as $child) { > > > >> $child->error = "Foo"; > > > >> $error = $child->validate(); > > > >> if ($error) { > > > >> $this->errors_exist = 1; > > > >> array_push ($errors, $error); > > > >> } > > > >>} > > > >> } > > > >> > > > >> $this->errors = $errors; > > > >> } > > > >> > > > >> The $this->children attribute should be an array of (references > > > > > > to) > > > > > > >> objects. > > > >> > > > >> I think somehow in the foreach ($this->children as $child) the > > > >>objects are > > > >> being copied, as $child->validate(); seems not to effect the > > > >>original > > > >> objects. > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] FYI: Specific References Incident
>From PHP Cookbook: for ($c = 0; $c < count($topics); $c++) { ... } Only way to do it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]