annoying parse error

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

Post Reply
hag
Forum Newbie
Posts: 10
Joined: Tue Apr 06, 2010 10:51 pm

annoying parse error

Post by hag »

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

Re: annoying parse error

Post by hag »

Coffee fixes everything.

Needed single quotes:

$index->setButtonArray( ' "Home"=>"index.php", "Contact"=>"contact/", "Privacy"=>"privacy/", "Site Map"=>"sitemap/" ' );

Hag
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: annoying parse error

Post by requinix »

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

Re: annoying parse error

Post by hag »

@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
Post Reply