473,395 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

$this = OtherClass::modifyMe($this) on construction

guillermobytes
Hi everyone,

is it possible to modifiy the $this value of $this within the construction:
SomeClass:
Expand|Select|Wrap|Line Numbers
  1. public function __construct($param)
  2. {
  3.     $this = OtherClass::modifyMe($this);
  4. }

OtherClass:
Expand|Select|Wrap|Line Numbers
  1. public static function modifyMe(SomeClass $object)
  2. {
  3.     //do some checks to se if $object has everything ok
  4.     //code .... 
  5.     //then set $object members
  6.     if (everything is ok) {
  7.         $object->imOk(true);
  8.         $object->iHaveValidMembers(true);
  9.     } else {
  10.         $object->imOk(false);
  11.         $object->iHaveValidMemers(false);
  12.     }
  13.     return $object;
  14. }
can i do this?
-do i have to integrate the modifyMe() function to SomeClass and then update the SomeClass instance members from there?
-do i have to make the checks from other places and then update the object pointer? ex:
Expand|Select|Wrap|Line Numbers
  1. $myObject = new SomeClass();
  2. $myObject = OtherClass::modifyMe($myObject);
  3.  
thank you for your help!
Jan 28 '10 #1

✓ answered by kovik

Your OtherClass::modifyMe() method will already modify the object that it receives. There's no need to reassign $this.

5 1415
Found answer: cannot re-assign $this on construction
Jan 28 '10 #2
Dormilich
8,658 Expert Mod 8TB
It wouldn’t make sense anyway.
Jan 28 '10 #3
Markus
6,050 Expert 4TB
You cannot reassign $this anywhere!
Jan 28 '10 #4
kovik
1,044 Expert 1GB
Your OtherClass::modifyMe() method will already modify the object that it receives. There's no need to reassign $this.
Jan 28 '10 #5
you're right since objects are passed by reference..
i completely forgot that!
thank you
Mar 7 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Anthony | last post by:
Hi, Can anyone help me out here, I'm looking for a design (pattern?) for a-synchronic construction of a class. I need this design in a framework which will run in a multithreaded system. I...
1
by: Allen | last post by:
I am trying to add an additional photo/hyperlink to the company web site (I didn't create it) without any luck. The mouseover feature 'highlights' pics by swapping them with another pic using this...
2
by: Steve | last post by:
Hi Folks, Sorry for this stupid question, but how do you handle errors during class construction. In other words, if I have a class that loads a file, and during loading, an error occurs, how do...
14
by: trying_to_learn | last post by:
i am on the chapter on copy construction in C++ in the code (see below), the author says if u pass the object by value as in HowMany h2 = f(h); ....then a bitwise object is created w/o calling...
15
by: Alfonso Morra | last post by:
Hi, I have some code from an example, that I want to retrofit into my project. The code from the example has the following line: SharedAppenderPtr myAppender( new...
3
by: Woody Splawn | last post by:
Does anyone know where I can find an under construction logo or icon?
4
by: robinsand | last post by:
Header File: car.h #if !defined CAR_H #define CAR_H enum TCarType { ctEconomy = 1, ctCompact, ctStandard, ctFullSize, ctMiniVan, ctSUV }; class Car { public: Car();
7
by: BeautifulMind | last post by:
In case of inheritence the order of execution of constructors is in the order of derivation and order of destructor execution is in reverse order of derivation. Is this case also true in case...
15
by: Victor Bazarov | last post by:
Hello, Take a look at this program: ----------------------------------- class B { B(const B&); B& operator=(const B&); public: B(int);
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.