Parse Errors

Posted on 2006-05-10
Last Modified: 2010-05-18
I bought a book from Wiley Publishing which included a ton of PHP / MySQL Examples.

None of the code seems to work on a Windows or Linux box.

In the following code lines 9, 10, 15, 18 and 44 all state that I have a Parse error. The other consistent part is this;
session_user()-> in all 5 lines

Any Help here would be Great and Thanks!

print start_page('Project Management Example');

$query = 'select p.project_id, p.project, p.due_dt
            , if(p.owner_id=?,1,0) as is_owner
      from projects p
$bind = array(session_user()->user_id);
if (!session_user()->is_admin())
      $query .= ' , project_user_map m
            where p.project_id = m.project_id and m.user_id = ?
      $bind[] = session_user()->user_id;
$query .= ' order by is_owner desc, p.due_dt ';
$rows = session_user()->dbh()->getAll($query, $bind);

$links = array();
$done_id = Status::status_id('done');
$cancelled_id = Status::status_id('cancelled');
$slipped_id = Status::status_id('slipped');
foreach ($rows as $row)
      extract($row, EXTR_OVERWRITE|EXTR_PREFIX_ALL, 'p');
      $tlinks = array();
      $tlinks[] = anchor_tag(
            , 'Calendar'
      $tlinks[] = anchor_tag(
            , 'Task List'
      $query = 'select t.*, u.user as owner
            from tasks t left join users u on t.owner_id = u.user_id
            where t.project_id = ?
                  and t.status_id <> ?
                  and (t.due_dt >= curdate() - interval 3 day
                        and t.due_dt <= curdate() + interval 3 day)
      $bind = array($p_project_id, $cancelled_id);
      $events = session_user()->dbh()->getAll($query,$bind);
Question by:resolvco
    LVL 49

    Expert Comment

    Shouldn't it be something like
    $session_user = session_user();

    $bind = array($session_user->id);

    LVL 142

    Accepted Solution

    what version of PHP do you use?
    i think this syntax only works as from PHP 5 on, but not sure...
    LVL 13

    Expert Comment

    I think we would need to see the function 'session_user()' to be able to solve this one, since it is not a built in PHP function.

    Author Comment


    Author Comment

    Okay also, on those lines shouldn't the operator be => and not ->?

    When Changing it and running it I get:

    "unexpected t_double_arrow"

    Here's the Function:

    function session_user()
          if (!isset($_SESSION))
                global $_SESSION;

          if (empty($_SESSION['user']) || !($_SESSION['user'] instanceof User))
                $_SESSION['user'] = new User;

          return $_SESSION['user'];

    LVL 13

    Expert Comment

    The '->' operator is the PHP Object Oriented Programming (OOP) method for accessing class methods/properties/etc... but can also be used for calling functions.  I'm not sure what they're trying to do in this script.  I agree with AngelIII - I don't think you can use this OOP method in PHP < 5.  I'm also not quite sure how to translate it to PHP 4.x.

    Author Comment

    That was it, PHP5. The Book I got the samples from was written previous to PHP5, why they would then put a CD together and release the code with PHP5 projects!?!?!?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to count occurrences of each item in an array.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now