PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
hag
Forum Newbie
Posts: 10 Joined: Tue Apr 06, 2010 10:51 pm
Post
by hag » Mon May 03, 2010 7:21 pm
Have I been staring at this too long and overlooking the obvious? Why do I keep getting a parse error?
index.php - exerpt
Code: Select all
<?php
require_once("page_base.php");
$index = new Page_Base();
//several $index-> sections to build each page's unique elements
$index->setButtonArray("Home"=>"index.php", "Contact"=>"contact/", "Privacy"=>"privacy/", "Site Map"=>"sitemap/");
?>
page_base.php - exerpt
Code: Select all
<?php
class Page_Base
{
//succinct listing
protected $_buttons;
public function setButtonArray($buttons)
{
$this->_buttons = array($buttons);
}
?>
Any help is appreciated, thank you.
Hag
hag
Forum Newbie
Posts: 10 Joined: Tue Apr 06, 2010 10:51 pm
Post
by hag » Mon May 03, 2010 7:44 pm
Coffee fixes everything.
Needed single quotes:
$index->setButtonArray( ' "Home"=>"index.php", "Contact"=>"contact/", "Privacy"=>"privacy/", "Site Map"=>"sitemap/" ' );
Hag
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Mon May 03, 2010 8:26 pm
That works? Weird. I would have said
Code: Select all
$index->setButtonArray(array("Home"=>"index.php", "Contact"=>"contact/", "Privacy"=>"privacy/", "Site Map"=>"sitemap/"));
hag
Forum Newbie
Posts: 10 Joined: Tue Apr 06, 2010 10:51 pm
Post
by hag » Tue May 04, 2010 8:22 pm
@tasairis:
Your idea would have worked as well if I rewrote the setButtonArray method.
I currently have the method building the array from the setButtonArray item list. My thinking is that this way I can change the method and not have to rewrite the middleware.
Thanks for the feedback.
Hag