PHP code problem

Posted on 2006-04-28
Last Modified: 2008-03-06
Hi All,

Whenever I try to check my PHP syntax below using my PHP Editor, I get the following error:

Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION on line 15

Where line 15 is the line (  $DBCls = &New clsDB; ) can someone please tell me exactly what I am doing wrong here?

require_once '../include/db.class.php';   //This is the DB class (clsDB)...

class SimplePoll

    var $DataBase;
    var $ActivePoll;

    $DBCls = &New clsDB;  //Line 15, here is where the problem appear.



Thanks in advance for your time
Question by:GiantMatrix
    LVL 20

    Expert Comment

    $DBCls = &New clsDB;

    should it be like this ?

     $DBCls =$New clsDB;
    LVL 10

    Expert Comment

    Why aren't we trying this?

    $DBCls=new clsDB();   //assuming that db.class.php has clsDB as class name.

    Did I miss anything here?

    LVL 16

    Expert Comment

    if for some reason u want to assign $DBCls to the address of a new object, then

    $DBCls = &New clsDB();

    but this is depricated
    LVL 49

    Accepted Solution


    You class cannot have inline code. All instructions should be included in functions:

    class SimplePoll {
       var $a;
       var $b;
       function c() {$c1 = 1;}
       function d() {$d1 = 1}

    I think you are looking for

    class SimplePoll {
      var $db;
      function SimplePoll () { //constructor, called when you do $somevar = new SimplePoll();
        $this->db = New clsDB();


    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

    Join & Write a Comment

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    732 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

    25 Experts available now in Live!

    Get 1:1 Help Now