473,378 Members | 1,492 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,378 software developers and data experts.

Referencing returned objects directly

Hi all,

Is it possible to directly reference an object that is returned by a
function in PHP?

ie this:
echo ReturnAnObject()->SomeMember;

instead of this:
var $Object = ReturnAnObject();
echo $Object->SomeMember;

'cus I can't work out the syntax if it is. :-(

Cheers,
Lister

Mar 19 '07 #1
2 1069
On Mar 19, 10:59 am, "lister" <listerofsme...@hotmail.comwrote:
Hi all,

Is it possible to directly reference an object that is returned by a
function in PHP?

ie this:
echo ReturnAnObject()->SomeMember;

instead of this:
var $Object = ReturnAnObject();
echo $Object->SomeMember;

'cus I can't work out the syntax if it is. :-(

Cheers,
Lister
This code works fine for me:

<?php
class foo {
public $bar = 'bar';
}

function baz() {
return new foo();
}

echo baz()->bar;
?>

Mar 19 '07 #2
On Mar 19, 12:45 pm, "ZeldorBlat" <zeldorb...@gmail.comwrote:
On Mar 19, 10:59 am, "lister" <listerofsme...@hotmail.comwrote:
Hi all,
Is it possible to directly reference an object that is returned by a
function in PHP?
ie this:
echo ReturnAnObject()->SomeMember;
instead of this:
var $Object = ReturnAnObject();
echo $Object->SomeMember;
'cus I can't work out the syntax if it is. :-(
Cheers,
Lister

This code works fine for me:

<?php
class foo {
public $bar = 'bar';

}

function baz() {
return new foo();

}

echo baz()->bar;
?>
I think it only works in PHP 5+ not in PHP 4. WIth PHP 4 you have to
set it to a variable then use that variable to call the function as
you have in your OP.

Mar 20 '07 #3

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

Similar topics

11
by: Milind | last post by:
Hi, I was trying to implement a composition relation, somthing of the following type: class A { public: class B {
4
by: John Spiegel | last post by:
Hi all (again), Next question: I have a Web user control contained in a page. How would I go about referencing the other objects in the page from within the control? One way seems to use...
2
by: Terry | last post by:
What is the syntax for referencing the properties of objects within Collections of objects? EXAMPLE: Dim MCoil As New Coil MCoil = CoilCollection("3456") TextBox1.Text() = MCoil.CoilDesc ...
5
by: Ian Meakin | last post by:
I am trying to consume a web service i have written. The web service returns to the client an array of objects. The web service when tested via inetrnet explorer retruns the correct xml data. I...
3
by: Varangian | last post by:
I made an MFC DLL in C++ . I want to reference it in C#. However I don't know where to put the function to be called from C# ? After referencing the DLL no methods are visible in the C# object...
3
by: gary | last post by:
Hi, I am trying to reference an anchor in a user control with a url. This worked in 1.1 but no longer works in 2.0. The ascx control is located in a "/include" folder If you have a...
17
by: Paul Helmuth | last post by:
All, (here's an easy one)... This is probably a stupid question - please bare with me as I am new to dotNet. How does one reference objects on a form from a module? In 6.0 you could simply...
3
by: Divick | last post by:
I was reading this section in Bruce Eckel's book which talks about passing and returning large objects ( Chapter 11: References & the Copy-Constructor ), where he explains that how to return big...
0
by: terminator | last post by:
first: I find the 'r/l-value reference' terminology rather confusing and I find the following names for this new refrence type more suitable: temporary reference: Since it is generally intended...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.