473,403 Members | 2,183 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,403 software developers and data experts.

OO - Accessing method in returned class without instance variable

Hi!

<?
class Foo {
function getMessage() {
return "foo";
}
}
class Bar {
function getFoo() {
return new Foo();
}
}
$bar = new Bar();
echo $bar->getFoo()->getMessage();
?>

Running this you will get a parse error on the line with:

echo $bar->getFoo()->getMessage();

In an object oriented manner I would like to argue that this expression is
completely valid. However it won't work in PHP and it annoys me. Is there
any other way of doing it without using a variable?
i.e.
$foo = $bar->getFoo();
$foo->getMessage();

The reason I don't want to use another variable is that I want to be able to
say:

<?=$bar->getFoo()->getMessage()?>.

All the best,

--
Erik Andersson ( E.N.E IT - Australia )
http://www.eneit.com/
- Australian, high quality web hosting from AU$4.95, all features included.
Jul 17 '05 #1
2 2503
Erik Andersson wrote:

<snip>
echo $bar->getFoo()->getMessage(); <snip> Running this you will get a parse error on the line with:

echo $bar->getFoo()->getMessage();

In an object oriented manner I would like to argue that this expression is
completely valid. However it won't work in PHP and it annoys me. Is there
any other way of doing it without using a variable?
That syntax is not valid in PHP4. You may have a better luck with PHP5.
The reason I don't want to use another variable is that I want to be able
to say:

<?=$bar->getFoo()->getMessage()?>.


You have to use 2 statements instead of 1, like you guessed.
Jul 17 '05 #2

Uzytkownik "Zurab Davitiani" <ag*@mindless.com> napisal w wiadomosci
news:MZ*******************@newssvr25.news.prodigy. com...
Vamat certification wrote:

<snip>
echo $bar->getFoo()->getMessage(); <snip>
Running this you will get a parse error on the line with:

echo $bar->getFoo()->getMessage();

In an object oriented manner I would like to argue that this expression is
completely valid. However it won't work in PHP and it annoys me. Is there any other way of doing it without using a variable?


That syntax is not valid in PHP4. You may have a better luck with PHP5.
The reason I don't want to use another variable is that I want to be able to say:

<?=$bar->getFoo()->getMessage()?>.


You have to use 2 statements instead of 1, like you guessed.

Shawn Wilson" <sh***@glassgiant.com> wrote in message
news:3F***************@glassgiant.com... Sticks wrote:
[re-ordered you post because top-posting is evil :o)]
<xyzzy> wrote in message news:Xf********************@comcast.com...

"Sticks" <sa**********@yahoo.com> wrote in message
news:3f********@usenet.per.paradox.net.au...
> ok... im not quite sure how to describe my problem.
> i have a php script that runs through my entire php site and writes the > resulting output to html files. this is necessary as the nature of the > hosting available to me for this particular page prohibits me from using > php/mysql as i would like.
>
> my script works simply by using output buffers and an include
> the relevant section of code is as follows:
>
> ob_start();
> include($source.$pagename);
> $page_buffer = ob_get_contents();
> ob_end_clean();
>
> i was wondering if there is a way i can do this without using the include,
> because the script only works when it is in the same directory as the site.
> this arrangement does not suit me, as i would rather be able to store
the
> script in a separate folder.
>
>
>
>
>
My first thought is to create an array with your directory names that
you want to scan

$allDirs =

array("/usr/local/apache/htdocs","/usr/local/apache/site1/","/usr/local/apac
he/site1/htdocs") etc...

then iterate through the array and subsequent directory files.

while (list(,$dirName) = each($allDirs) {
// create an array of all files
$allFiles = scandir($dirName);
while (list ($key,$fileName) = each($allFiles) {
// each file within each directory
$page_buffer to $fileName stuf......
}
}

perhaps i havent been clear enough
i dont want to use includes to perform this task. i would like to get

the html output of a php script that is quite complicated and uses a variety of includes of its own which i do not wish to rewrite unless i absolutely have to. these includes are disturbed when my script resides in a different
directory to the page.

as it stands, the script works. it just isnt an ideal solution.
i am looking for something along the lines of the exec() command, only for executing php scripts.


I'm not sure I understand your problem, but if you want to execute php

scripts on Linux, you can use

/pathinfo/php -q /pathinfo/scriptname.php

from the command line or a cron job. The "-q" suppresses HTTP headers. Or you could do:

/pathinfo/php -q /pathinfo/scriptname.php > index.html

to send all output from that php script to a file called index.html. Be careful with this, though, as it's easy to overwrite the wrong files...

Jul 17 '05 #3

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

Similar topics

4
by: DDE | last post by:
Hi All, Reformulating a problem from a previous post: How can I access an application variable from a static method? When I try: string myString = Application{"thisString"].ToString; ...
5
by: Mike Oliszewski | last post by:
Given the following c# code: namespace Company2 { public class SomeFunctions { public void FunctionA() { // Do Something. }
5
by: hellrazor | last post by:
Hi, (new to webservices here) Is it possible to access a class instance variable defined in a webservice? I want to access this variable, in addition to the data being returned by the . so...
13
by: Maxim | last post by:
Hi! A have a string variable (which is a reference type). Now I define my Method like that: void MakeFullName(string sNamePrivate) { sNamePrivate+="Gates" }
8
by: dwok | last post by:
I have been wondering this for a while now. Suppose I have a class that contains some private member variables. How should I access the variables throughout the class? Should I use properties that...
5
by: Andy | last post by:
I'm having trouble accessing an unmanaged long from a managed class in VC++.NET When I do, the contents of the variable seem to be mangled. If I access the same variable byte-by-byte, I get the...
19
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; ...
12
by: titan nyquist | last post by:
I have a class with data and methods that use it. Everything is contained perfectly THE PROBLEM: A separate thread has to call a method in the current instantiation of this class. There is...
11
by: eBob.com | last post by:
I have this nasty problem with Shared methods and what I think of as "global storage" - i.e. storage declared outside of any subroutines or functions. In the simple example below this "global"...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.