473,499 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cannot re-assign $this ...

dear folks,

I'm one more guy having the cannot re-assign $this problem.

someone left a php4 file here containing the lines

| function linkbar()
| {
| if(func_num_args() == 1)
| {

| $this = func_get_arg(0);
| return;
}
...
| }

inside a php4 class definition. func_get_arg(0) in this case delivers
an object - working fine in php4. I struggled a bit with the &
referencing (while not really understanding it and the problem) but
gave up. how must I modify the code to get it to work in php5?

thank you very much!!

daniel

Feb 20 '07 #1
3 7254
Hi Daniel,

given the note of Wolverine on
http://nl2.php.net/manual/en/language.oop.php
it seems like assinging $this will cause the assigned value to be
returned. When you replace
$this = func_get_arg(0);
return;
by
return func_get_arg(0);

you shoud get the same results in php4 and it should work in php5 too.

greetings,

Henk Verhoeven,
www.pphPeanuts.org.

Daniel Loose wrote:
dear folks,

I'm one more guy having the cannot re-assign $this problem.

someone left a php4 file here containing the lines

| function linkbar()
| {
| if(func_num_args() == 1)
| {

| $this = func_get_arg(0);
| return;
}
...
| }

inside a php4 class definition. func_get_arg(0) in this case delivers
an object - working fine in php4. I struggled a bit with the &
referencing (while not really understanding it and the problem) but
gave up. how must I modify the code to get it to work in php5?

thank you very much!!

daniel
Feb 20 '07 #2
On Tue, 20 Feb 2007 23:15:09 +0100, Henk Verhoeven
<ne***@phppeanutsREMOVE-THIS.orgwrote:
When you replace
$this = func_get_arg(0);
return;
by
return func_get_arg(0);

you shoud get the same results in php4 and it should work in php5 too.
hm, thank you hank, however this is not the solution. of course it
removes the cannot reassign error msg, but gives another errror in
another line that wants to access the object (by using $this again)
("Call to a member function initLink() on a non-object ") I'm not an
expert here but I don't think that return func... does the same as the
original code... :-)

hoping for any other ideas,
daniel

Feb 21 '07 #3
Rik
Daniel Loose wrote:
Henk Verhoeven wrote:
>When you replace
$this = func_get_arg(0);
return;
by
return func_get_arg(0);

you shoud get the same results in php4 and it should work in php5 too..

hm, thank you hank, however this is not the solution. of course it
removes the cannot reassign error msg, but gives another errror in
another line that wants to access the object (by using $this again)
("Call to a member function initLink() on a non-object ") I'm not an
expert here but I don't think that return func... does the same as the
original code... :-)
Well, unfortunately, I have no solution for you. Then again, I'm not that
well versed in OO, but this seems Bad Practise to me. A hidious, hidous,
hidous quick fix could be, if the object is a global, to use this function
instead:

function evil_switch_object($name,$object){
$GLOBALS[$name] = $object;
}

Then again, I can not find the logic to switch WHY this is not done like:

$foo = new foo();//first class/object
$bar = new bar();//second class/object
$foo = $bar;//instead of $foo->linkbar($bar);

Could you go into further detail as to why this exact construct is needed?
Seems illogical...
--
Rik Wasmus
Feb 21 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3330
by: Krista | last post by:
Hi guys, i have a problem about inserting data into the table. I dont know why the output always said cannot be added to the database! Anyone has idea for me? i check the connect is ok, but dont...
8
3199
by: JZ | last post by:
I cannot find out what is the problem with my Python. I cannot join to smtp host. > python Python 2.3.4 (#1, Jun 22 2004, 04:42:42) on linux2 Type "help", "copyright", "credits" or "license"...
1
1849
by: Ram | last post by:
Hey, I have a solution that is built from both C# and VB.Net projects that some C# projects are referenced to VB.Net projects and vise versa. Whenever I try to rebuild my solution I get the...
7
4520
by: Joe | last post by:
I have an upload file operation in the web application. UploadForm.asp is the form, and UploadAction.asp is the form processing. //UploadForm.asp <FORM NAME="InputForm"...
1
3616
by: Chris | last post by:
I built small C# Web and Web Service applications in a training class last week. The applications worked in the class, but when I tried to run them again over the weekend, they both bombed....
6
8900
by: Grant | last post by:
Hi, I'm trying to setup a web server to host asp.net 1.1... but keep getting the following error message: Hopefully someone can give me some ideas on what I may need to do. Thanks in...
3
16469
by: David T. Ashley | last post by:
Hi, Red Hat Enterprise Linux 4.X. I'm writing command-line PHP scripts for the first time. I get the messages below. What do they mean? Are these operating system library modules, or...
1
4669
by: kw.housing | last post by:
I have all the library already in path: $ ls -l /opt/IBM/db2/lib64 | grep libdb2o -r-xr-xr-x 1 bin bin 7757295 Jul 12 2006 libdb2osse.a* -r--r--r-- 1 bin bin ...
10
13050
by: CodeNoob | last post by:
please help been working on a project got it down to 5 errors from 100 now i have no idea what to do. Errors: init: deps-jar: Created dir: C:\Users\Tommy\Desktop\build\classes Compiling 306...
3
3157
by: Sindhu Rani | last post by:
i hav created 3 classes in 3 different files. am gettin an error durin compilation. wat shud i do??? C:\s\source>javac -d ..\classes devtestdrive.java devtestdrive.java:5: cannot resolve symbol...
0
7134
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
7012
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7225
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...
0
7392
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5479
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3101
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
307
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.