Page 1 of 1

annoying parse error

Posted: Mon May 03, 2010 7:21 pm
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

Re: annoying parse error

Posted: Mon May 03, 2010 7:44 pm
by hag
Coffee fixes everything.

Needed single quotes:

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

Hag

Re: annoying parse error

Posted: Mon May 03, 2010 8:26 pm
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/"));

Re: annoying parse error

Posted: Tue May 04, 2010 8:22 pm
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