SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Nov 2002
    Location
    Dubai
    Posts
    714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Generating a page using a class

    I am trying to generate a page with the help of the following code for home.php which uses a Class.

    The code for my page home.php is as follows:

    PHP Code:
    <?php
      
    require ('page.inc');
      
    $homepage = new Page(); // This is the line where the error is shown
      
      
    $homepage -> SetContent('<p>Welcome to the home of TLA Consulting.
                             Please take some time to get to know us.</p>
                             <p>We specialise in serving your business needs
                             and hope to hear from you soon.</p>'
                             
    );
      
    $homepage -> Display();
    ?>
    But I am getting an error like this.

    Fatal error: Cannot instantiate non-existent class: page in c:\ncdtree\my documents\php\example scripts\welling thompson\home.php on line 8

    I am also getting a parse error in my script for php.inc.

    Parse error: parse error, unexpected T_STRING, expecting ')' in c:\ncdtree\my documents\php\example scripts\welling thompson\page.inc on line 10

    I am giving the required portion of the script for page.inc below:


    PHP Code:
    <?php
    class Page
    {
      
    // class Page's attributes
      
    var $content;
      var 
    $title 'TLA Consulting Pty Ltd';
      var 
    $keywords 'TLA Consulting, Three Letter Abbreviation,
                       some of my best friends are search engines'
    ;
      var 
    $buttons = array( 'Home'     => 'home.php',
                            
    'Contact   => 'contact.php',  // This is line 10 where the error is mentioned.
                            '
    Services  => 'services.php',
                            
    'Site Map  => 'map.php'
                          );
    Can anyone help me?

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey
    Its telling you exactly where the error is:

    Code:
      'Contact   => 'contact.php',


    It should be
    Code:
    'Contact'   => 'contact.php',

    See, there is missing '

    Hope this helps.


  3. #3
    *munch munch* killerkooki's Avatar
    Join Date
    Sep 2004
    Location
    Singapore
    Posts
    405
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are missing an single quotation mark in your array key.
    'Contact' => 'contact.php',

  4. #4
    SitePoint Guru
    Join Date
    Nov 2002
    Location
    Dubai
    Posts
    714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sannu, killerkooki

    Thanks a lot to both of you. It was a very silly syntax error, which I did not figure out. I had made a few more syntax errors in a few more lines which I corrected and now my page is working.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •