Concatenating object methods
- From: "crater" <iccarter@xxxxxxxxxxxxx>
- Date: 31 Jan 2007 08:45:39 -0800
I'm using PHP 5.2.
I've created classes to embody HTML elements for a particular project
I'm currently working on.
All setter methods in the classes return $this so that I can string
the
methods together in an attempt to reduce "page bloat".
[code]
// create a text link
$link1 = new htmlElement("a");
$link1->addAttribute("href", "http://homepages.nildram.co.uk/
~iccarter")
->addAttribute("target","_blank")->addAttribute("name",
"htmlElement1");
echo $link1->addContent("My personal web site")."<br><br>\n";
[/code]
My anchor element is duly output exactly as expected.
A question naturally arises from this. Is there a way to do the
following?...
[code]
$link1 = new htmlElement("a")->setAttribute("name", "value");
or
($link1 = new htmlElement("a"))->setAttribute("name", "value");
[/code]
It's not an issue. I'm just curious.
.
- Follow-Ups:
- Re: Concatenating object methods
- From: bob.chatman@xxxxxxxxx
- Re: Concatenating object methods
- From: Michael Fesser
- Re: Concatenating object methods
- From: Tom
- Re: Concatenating object methods
- Prev by Date: Re: redirection question
- Next by Date: Re: redirection question
- Previous by thread: Newlines don't work.
- Next by thread: Re: Concatenating object methods
- Index(es):