[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP code problem

Posted on 2006-04-28
4
Medium Priority
?
951 Views
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; ) ...so 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
0
Comment
Question by:GiantMatrix
4 Comments
 
LVL 20

Expert Comment

by:Gawai
ID: 16567470
$DBCls = &New clsDB;

should it be like this ?

 $DBCls =$New clsDB;
0
 
LVL 10

Expert Comment

by:iamanindian
ID: 16567898
Hmnn...
Why aren't we trying this?

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


Did I miss anything here?

Regards
WC
0
 
LVL 16

Expert Comment

by:dr_dedo
ID: 16569343
if for some reason u want to assign $DBCls to the address of a new object, then

$DBCls = &New clsDB();

but this is depricated
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 2000 total points
ID: 16569378
Hi,

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();
  }
}

-r-
-r-
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month19 days, 20 hours left to enroll

873 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