473,320 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Use of variables in classes

I've written a simple class that puts together a MySQL SELECT query and
allows you to extend the query, but I'm unsure as to when to use $this - >
var_name and when I can just use $varname, and when it's necessary to use
'var $varname' and when this can be left out.
Here's the class - could it be made simpler?
Michael

class select_query_builder {
// class to put together and add to a select query
var $query;
var $select;
var $from;
var $where;
var $orderby;
var $distinct;
var $t_select;
var $t_from;
var $t_where;
var $t_orderby;

function select_query_builder($select, $from, $where='', $orderby ='') {
// each variable is an array

$this -> select = $select;
$this -> from = $from;
$this -> where = $where;
$this -> orderby = $orderby;

$this -> t_select = $select;
$this -> t_from = $from;
$this -> t_where = $where;
$this -> t_orderby = $orderby;
}

// add additional elements to the query
function extend_query($what, $newinfo)
{
$this -> {'t_'.$what} = array_merge($this -> {'t_'.$what}, $newinfo);
}

// return the complete query;
function return_query() {
$this -> query = 'SELECT '$this -> distinct.' '.implode(', ', $this ->
t_select).' FROM '.implode(', ', $this -> t_from);

if (!empty($this -> t_where)) {
$this -> query .= ' WHERE '.implode(' AND ', $this -> t_where);
}

if (!empty($this -> orderby)) {
$this -> query .= ' ORDER BY '.implode(' ASC, ', $this -> t_orderby).'
ASC';
}

return $this -> query;

}

function reset_to_before_extend() {

$this -> t_select = $this -> select;
$this -> t_from = $this -> from;
$this -> t_where = $this -> where;
$this -> t_orderby = $this -> orderby;
}
}
Jul 17 '05 #1
15 2106
Take a look at http://www.tonymarston.co.uk/php-mys...seobjects.html
for some tips on this subject.

--
Tony Marston

http://www.tonymarston.net
"Michael" <le*****@britishlibrary.net> wrote in message
news:c8**********@hercules.btinternet.com...
I've written a simple class that puts together a MySQL SELECT query and
allows you to extend the query, but I'm unsure as to when to use $this - >
var_name and when I can just use $varname, and when it's necessary to use
'var $varname' and when this can be left out.
Here's the class - could it be made simpler?
Michael

class select_query_builder {
// class to put together and add to a select query
var $query;
var $select;
var $from;
var $where;
var $orderby;
var $distinct;
var $t_select;
var $t_from;
var $t_where;
var $t_orderby;

function select_query_builder($select, $from, $where='', $orderby ='') {
// each variable is an array

$this -> select = $select;
$this -> from = $from;
$this -> where = $where;
$this -> orderby = $orderby;

$this -> t_select = $select;
$this -> t_from = $from;
$this -> t_where = $where;
$this -> t_orderby = $orderby;
}

// add additional elements to the query
function extend_query($what, $newinfo)
{
$this -> {'t_'.$what} = array_merge($this -> {'t_'.$what}, $newinfo);
}

// return the complete query;
function return_query() {
$this -> query = 'SELECT '$this -> distinct.' '.implode(', ', $this ->
t_select).' FROM '.implode(', ', $this -> t_from);

if (!empty($this -> t_where)) {
$this -> query .= ' WHERE '.implode(' AND ', $this -> t_where);
}

if (!empty($this -> orderby)) {
$this -> query .= ' ORDER BY '.implode(' ASC, ', $this -> t_orderby).'
ASC';
}

return $this -> query;

}

function reset_to_before_extend() {

$this -> t_select = $this -> select;
$this -> t_from = $this -> from;
$this -> t_where = $this -> where;
$this -> t_orderby = $this -> orderby;
}
}

Jul 17 '05 #2
"Michael" <le*****@britishlibrary.net> wrote in message
news:c8**********@hercules.btinternet.com...
I've written a simple class that puts together a MySQL SELECT query and
allows you to extend the query, but I'm unsure as to when to use $this - >
var_name and when I can just use $varname, and when it's necessary to use
'var $varname' and when this can be left out.
Here's the class - could it be made simpler?
Michael


Why would you want to do that though? The whole point of declarative
languages like SQL is to avoid the kind of complex code that you're writing.
Jul 17 '05 #3
I have a form which allows people to search a database of tutorials by any
combination of location, tutor, subject or date.
Using this class I can set a number of columns, tables and 'WHERE' clauses
that re-occur in every possible search when I initiate the class, then
simply add to the query as necesary for each possible search criteria
combination. Although in terms of code the class is more complex than a
series of conditional statements, by abstracting it, it makes it the code on
the page much easier to understand and therefore easier and quicker to
update.
"Chung Leong" <ch***********@hotmail.com> wrote in message
news:Hp********************@comcast.com...
"Michael" <le*****@britishlibrary.net> wrote in message
news:c8**********@hercules.btinternet.com...
I've written a simple class that puts together a MySQL SELECT query and
allows you to extend the query, but I'm unsure as to when to use $this -
var_name and when I can just use $varname, and when it's necessary to use 'var $varname' and when this can be left out.
Here's the class - could it be made simpler?
Michael


Why would you want to do that though? The whole point of declarative
languages like SQL is to avoid the kind of complex code that you're

writing.

Jul 17 '05 #4
"Michael" <le*****@britishlibrary.net> wrote in message
news:c8**********@sparta.btinternet.com...
I have a form which allows people to search a database of tutorials by any
combination of location, tutor, subject or date.
Using this class I can set a number of columns, tables and 'WHERE' clauses
that re-occur in every possible search when I initiate the class, then
simply add to the query as necesary for each possible search criteria
combination. Although in terms of code the class is more complex than a
series of conditional statements, by abstracting it, it makes it the code on the page much easier to understand and therefore easier and quicker to
update.


Abstraction would mean that the calling code isn't aware of the underlying
storage mechanism. This is clearly not the case here. All you have is a
class that limits what kind of query you can build.
Jul 17 '05 #5
Good point. Clearly I did not explain myself very well.
I don't see what you are getting at though - Are you suggesting that there
is a way to generate multiple related query statements just using SQL?
Michael

"Chung Leong" <ch***********@hotmail.com> wrote in message
news:TJ********************@comcast.com...
"Michael" <le*****@britishlibrary.net> wrote in message
news:c8**********@sparta.btinternet.com...
I have a form which allows people to search a database of tutorials by any combination of location, tutor, subject or date.
Using this class I can set a number of columns, tables and 'WHERE' clauses that re-occur in every possible search when I initiate the class, then
simply add to the query as necesary for each possible search criteria
combination. Although in terms of code the class is more complex than a
series of conditional statements, by abstracting it, it makes it the
code on
the page much easier to understand and therefore easier and quicker to
update.


Abstraction would mean that the calling code isn't aware of the underlying
storage mechanism. This is clearly not the case here. All you have is a
class that limits what kind of query you can build.

Jul 17 '05 #6
Dear Tony,
Thanks - Useful advice.
Michael

"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message
news:c8*******************@news.demon.co.uk...
Take a look at http://www.tonymarston.co.uk/php-mys...seobjects.html
for some tips on this subject.

--
Tony Marston

http://www.tonymarston.net
"Michael" <le*****@britishlibrary.net> wrote in message
news:c8**********@hercules.btinternet.com...
I've written a simple class that puts together a MySQL SELECT query and
allows you to extend the query, but I'm unsure as to when to use $this -

var_name and when I can just use $varname, and when it's necessary to use 'var $varname' and when this can be left out.
Here's the class - could it be made simpler?
Michael

class select_query_builder {
// class to put together and add to a select query
var $query;
var $select;
var $from;
var $where;
var $orderby;
var $distinct;
var $t_select;
var $t_from;
var $t_where;
var $t_orderby;

function select_query_builder($select, $from, $where='', $orderby ='') {
// each variable is an array

$this -> select = $select;
$this -> from = $from;
$this -> where = $where;
$this -> orderby = $orderby;

$this -> t_select = $select;
$this -> t_from = $from;
$this -> t_where = $where;
$this -> t_orderby = $orderby;
}

// add additional elements to the query
function extend_query($what, $newinfo)
{
$this -> {'t_'.$what} = array_merge($this -> {'t_'.$what}, $newinfo);
}

// return the complete query;
function return_query() {
$this -> query = 'SELECT '$this -> distinct.' '.implode(', ', $this ->
t_select).' FROM '.implode(', ', $this -> t_from);

if (!empty($this -> t_where)) {
$this -> query .= ' WHERE '.implode(' AND ', $this -> t_where);
}

if (!empty($this -> orderby)) {
$this -> query .= ' ORDER BY '.implode(' ASC, ', $this -> t_orderby).'
ASC';
}

return $this -> query;

}

function reset_to_before_extend() {

$this -> t_select = $this -> select;
$this -> t_from = $this -> from;
$this -> t_where = $this -> where;
$this -> t_orderby = $this -> orderby;
}
}


Jul 17 '05 #7

"Michael" <le*****@britishlibrary.net> wrote in message
news:c8**********@sparta.btinternet.com...
Good point. Clearly I did not explain myself very well.
I don't see what you are getting at though - Are you suggesting that there
is a way to generate multiple related query statements just using SQL?
Michael


All I'm saying you don't need a class to build a SQL statement.
Jul 17 '05 #8
You may be right - it works for me though - I wouldn't use it if I was just
building one query statement, but for a series of related statements, it
looks a lot better than, for example, the code below which was what
persuaded me to write a class when faced with a similar problem to solve for
another client - in my opinion interspersing lots of conditional statements
is a messy solution compared to the relative 'cleanness' of code that you
can get by using a class. I appreciate that using a class will actually mean
that the code will take longer to run than the example below, but I
personally I'm happy to accept a slight loss of speed if it means that the
code is easy to read and update.
$query = "SELECT ev.prd_id, UNIX_TIMESTAMP(date_start) AS date_start,
UNIX_TIMESTAMP(date_end) AS date_end, evd.eve_name, evd.eve_name2,
evd.eve_des_x, t.tut_name, t.tut_url, v.ven_name, ev.ctc_id, ctc.ctc_name,
v.ven_id, v.ven_town, v.ven_url, co.country_name, prc.price_unitcost,
prd.prd_forsale, dt.date_more_x, tl.tut_priority, tl.tut_more_x";

if ($pi) {$query .= ', dsc.eve_description';}

$query .= " FROM n_event ev, n_eventdetails evd, n_date dt, n_tutor t,
n_tutorlist tl, n_venue v, n_country co, n_price prc, n_product prd,
n_contacts ctc";

if ($sbj) {$query .= ', n_event_subject esbj';}

if ($pi) {$query .= ', n_eventdescription dsc';}

$query .= " WHERE prd.cat_id=1 AND prd.prd_id = ev.prd_id AND evd.eve_id =
ev.eve_id AND dt.prd_id = ev.prd_id AND tl.prd_id = ev.prd_id AND t.tut_id =
tl.tut_id AND v.ven_id = ev.ven_id AND co.country_id = v.country_id AND
prc.price_id = prd.price_id AND ev.ctc_id = ctc.ctc_id AND dt.date_priority
= 1 ";

if ((!$isildur) && (!$tpi)) { $query.=' AND UNIX_TIMESTAMP(date_end) >
(UNIX_TIMESTAMP(now())-86400) '; }

if ($tpi) { $query .= ' AND prd.prd_id = '.$tpi.' '; }
else {$query .= ' AND prd.prd_forsale = 1 ';}

if ($t) $query .= ' AND tl.tut_id ='.$t.' ';
else $query .= ' AND tl.tut_priority = 1';

if ($pi) $query .= ' AND dsc.eve_id = ev.eve_id';
Jul 17 '05 #9
And exactly how you wouldn't need if statement if you use the class? All it
does is implode the conditions together, which is perfectly doable without
the use of a class.

$conds[] = ($tpi) ? "prd.prd_id = $tpi" : "prd.prd_forsale = 1";
$conds[] = ($t) ? "tl.tut_id = $t" : "tl.tut_priority = 1";
$conds[] = ($pi) ? "dsc.eve_id = ev.eve_id" : null;
....
implode(" AND ", array_filter($conds));

The point I'm trying to make is that you're encapsulating at the wrong
level. Imploding a bunch of strings and attaching "AND" and "WHERE" is easy
stuff. The complexity is in the logic of the query not its syntax.
"Michael" <le*****@britishlibrary.net> wrote in message
news:c8**********@hercules.btinternet.com...
You may be right - it works for me though - I wouldn't use it if I was just building one query statement, but for a series of related statements, it
looks a lot better than, for example, the code below which was what
persuaded me to write a class when faced with a similar problem to solve for another client - in my opinion interspersing lots of conditional statements is a messy solution compared to the relative 'cleanness' of code that you
can get by using a class. I appreciate that using a class will actually mean that the code will take longer to run than the example below, but I
personally I'm happy to accept a slight loss of speed if it means that the
code is easy to read and update.
$query = "SELECT ev.prd_id, UNIX_TIMESTAMP(date_start) AS date_start,
UNIX_TIMESTAMP(date_end) AS date_end, evd.eve_name, evd.eve_name2,
evd.eve_des_x, t.tut_name, t.tut_url, v.ven_name, ev.ctc_id, ctc.ctc_name,
v.ven_id, v.ven_town, v.ven_url, co.country_name, prc.price_unitcost,
prd.prd_forsale, dt.date_more_x, tl.tut_priority, tl.tut_more_x";

if ($pi) {$query .= ', dsc.eve_description';}

$query .= " FROM n_event ev, n_eventdetails evd, n_date dt, n_tutor t,
n_tutorlist tl, n_venue v, n_country co, n_price prc, n_product prd,
n_contacts ctc";

if ($sbj) {$query .= ', n_event_subject esbj';}

if ($pi) {$query .= ', n_eventdescription dsc';}

$query .= " WHERE prd.cat_id=1 AND prd.prd_id = ev.prd_id AND evd.eve_id =
ev.eve_id AND dt.prd_id = ev.prd_id AND tl.prd_id = ev.prd_id AND t.tut_id = tl.tut_id AND v.ven_id = ev.ven_id AND co.country_id = v.country_id AND
prc.price_id = prd.price_id AND ev.ctc_id = ctc.ctc_id AND dt.date_priority = 1 ";

if ((!$isildur) && (!$tpi)) { $query.=' AND UNIX_TIMESTAMP(date_end) >
(UNIX_TIMESTAMP(now())-86400) '; }

if ($tpi) { $query .= ' AND prd.prd_id = '.$tpi.' '; }
else {$query .= ' AND prd.prd_forsale = 1 ';}

if ($t) $query .= ' AND tl.tut_id ='.$t.' ';
else $query .= ' AND tl.tut_priority = 1';

if ($pi) $query .= ' AND dsc.eve_id = ev.eve_id';

Jul 17 '05 #10
Well, to be honest I did not mean to suggest that I would not need if
statements, only that I would not need to have them interspersed in quite
such a messy way. What you've written does look very clean, so I have to
concede that using a class for this is overkill!
Sadly, I'm still not much wiser about the use of variables in classes. You
wouldn't happen to know anything about them would you?
Michael

"Chung Leong" <ch***********@hotmail.com> wrote in message
news:UK********************@comcast.com...
And exactly how you wouldn't need if statement if you use the class? All it does is implode the conditions together, which is perfectly doable without
the use of a class.

$conds[] = ($tpi) ? "prd.prd_id = $tpi" : "prd.prd_forsale = 1";
$conds[] = ($t) ? "tl.tut_id = $t" : "tl.tut_priority = 1";
$conds[] = ($pi) ? "dsc.eve_id = ev.eve_id" : null;
...
implode(" AND ", array_filter($conds));

The point I'm trying to make is that you're encapsulating at the wrong
level. Imploding a bunch of strings and attaching "AND" and "WHERE" is easy stuff. The complexity is in the logic of the query not its syntax.
"Michael" <le*****@britishlibrary.net> wrote in message
news:c8**********@hercules.btinternet.com...
You may be right - it works for me though - I wouldn't use it if I was just
building one query statement, but for a series of related statements, it
looks a lot better than, for example, the code below which was what
persuaded me to write a class when faced with a similar problem to solve

for
another client - in my opinion interspersing lots of conditional

statements
is a messy solution compared to the relative 'cleanness' of code that you can get by using a class. I appreciate that using a class will actually

mean
that the code will take longer to run than the example below, but I
personally I'm happy to accept a slight loss of speed if it means that the code is easy to read and update.
$query = "SELECT ev.prd_id, UNIX_TIMESTAMP(date_start) AS date_start,
UNIX_TIMESTAMP(date_end) AS date_end, evd.eve_name, evd.eve_name2,
evd.eve_des_x, t.tut_name, t.tut_url, v.ven_name, ev.ctc_id, ctc.ctc_name, v.ven_id, v.ven_town, v.ven_url, co.country_name, prc.price_unitcost,
prd.prd_forsale, dt.date_more_x, tl.tut_priority, tl.tut_more_x";

if ($pi) {$query .= ', dsc.eve_description';}

$query .= " FROM n_event ev, n_eventdetails evd, n_date dt, n_tutor t,
n_tutorlist tl, n_venue v, n_country co, n_price prc, n_product prd,
n_contacts ctc";

if ($sbj) {$query .= ', n_event_subject esbj';}

if ($pi) {$query .= ', n_eventdescription dsc';}

$query .= " WHERE prd.cat_id=1 AND prd.prd_id = ev.prd_id AND evd.eve_id = ev.eve_id AND dt.prd_id = ev.prd_id AND tl.prd_id = ev.prd_id AND t.tut_id =
tl.tut_id AND v.ven_id = ev.ven_id AND co.country_id = v.country_id

AND prc.price_id = prd.price_id AND ev.ctc_id = ctc.ctc_id AND

dt.date_priority
= 1 ";

if ((!$isildur) && (!$tpi)) { $query.=' AND UNIX_TIMESTAMP(date_end) >
(UNIX_TIMESTAMP(now())-86400) '; }

if ($tpi) { $query .= ' AND prd.prd_id = '.$tpi.' '; }
else {$query .= ' AND prd.prd_forsale = 1 ';}

if ($t) $query .= ' AND tl.tut_id ='.$t.' ';
else $query .= ' AND tl.tut_priority = 1';

if ($pi) $query .= ' AND dsc.eve_id = ev.eve_id';


Jul 17 '05 #11
The goal is to write code that is clear, not just looks clean.

Doing with variables in classes is fairly simple: you have to use $this->
all the time.

"Michael" <le*****@britishlibrary.net> wrote in message
news:c8**********@hercules.btinternet.com...
Well, to be honest I did not mean to suggest that I would not need if
statements, only that I would not need to have them interspersed in quite
such a messy way. What you've written does look very clean, so I have to
concede that using a class for this is overkill!
Sadly, I'm still not much wiser about the use of variables in classes. You
wouldn't happen to know anything about them would you?
Michael

"Chung Leong" <ch***********@hotmail.com> wrote in message
news:UK********************@comcast.com...
And exactly how you wouldn't need if statement if you use the class? All it
does is implode the conditions together, which is perfectly doable without
the use of a class.

$conds[] = ($tpi) ? "prd.prd_id = $tpi" : "prd.prd_forsale = 1";
$conds[] = ($t) ? "tl.tut_id = $t" : "tl.tut_priority = 1";
$conds[] = ($pi) ? "dsc.eve_id = ev.eve_id" : null;
...
implode(" AND ", array_filter($conds));

The point I'm trying to make is that you're encapsulating at the wrong
level. Imploding a bunch of strings and attaching "AND" and "WHERE" is

easy
stuff. The complexity is in the logic of the query not its syntax.
"Michael" <le*****@britishlibrary.net> wrote in message
news:c8**********@hercules.btinternet.com...
You may be right - it works for me though - I wouldn't use it if I was

just
building one query statement, but for a series of related statements, it looks a lot better than, for example, the code below which was what
persuaded me to write a class when faced with a similar problem to
solve for
another client - in my opinion interspersing lots of conditional

statements
is a messy solution compared to the relative 'cleanness' of code that you can get by using a class. I appreciate that using a class will
actually mean
that the code will take longer to run than the example below, but I
personally I'm happy to accept a slight loss of speed if it means that

the code is easy to read and update.
$query = "SELECT ev.prd_id, UNIX_TIMESTAMP(date_start) AS date_start,
UNIX_TIMESTAMP(date_end) AS date_end, evd.eve_name, evd.eve_name2,
evd.eve_des_x, t.tut_name, t.tut_url, v.ven_name, ev.ctc_id, ctc.ctc_name, v.ven_id, v.ven_town, v.ven_url, co.country_name, prc.price_unitcost,
prd.prd_forsale, dt.date_more_x, tl.tut_priority, tl.tut_more_x";

if ($pi) {$query .= ', dsc.eve_description';}

$query .= " FROM n_event ev, n_eventdetails evd, n_date dt, n_tutor t,
n_tutorlist tl, n_venue v, n_country co, n_price prc, n_product prd,
n_contacts ctc";

if ($sbj) {$query .= ', n_event_subject esbj';}

if ($pi) {$query .= ', n_eventdescription dsc';}

$query .= " WHERE prd.cat_id=1 AND prd.prd_id = ev.prd_id AND
evd.eve_id = ev.eve_id AND dt.prd_id = ev.prd_id AND tl.prd_id = ev.prd_id AND t.tut_id
=
tl.tut_id AND v.ven_id = ev.ven_id AND co.country_id = v.country_id

AND prc.price_id = prd.price_id AND ev.ctc_id = ctc.ctc_id AND

dt.date_priority
= 1 ";

if ((!$isildur) && (!$tpi)) { $query.=' AND UNIX_TIMESTAMP(date_end) (UNIX_TIMESTAMP(now())-86400) '; }

if ($tpi) { $query .= ' AND prd.prd_id = '.$tpi.' '; }
else {$query .= ' AND prd.prd_forsale = 1 ';}

if ($t) $query .= ' AND tl.tut_id ='.$t.' ';
else $query .= ' AND tl.tut_priority = 1';

if ($pi) $query .= ' AND dsc.eve_id = ev.eve_id';



Jul 17 '05 #12
> Doing with variables in classes is fairly simple: you have to use $this->
all the time.


That's one of the parts I'm confused about - clearly there are a lot of
instances
where variables are refered to just using $varname rather than $this ->
varname
within classes.
Michael
Jul 17 '05 #13
If you refer to $varname within a class method then that variable is local
only to that method.

If you refer to $this->varname then that variable is global to any method
within the class.

--
Tony Marston
http://www.tonymarston.net
"Michael" <le*****@britishlibrary.net> wrote in message
news:c8**********@sparta.btinternet.com...
Doing with variables in classes is fairly simple: you have to use $this-> all the time.


That's one of the parts I'm confused about - clearly there are a lot of
instances
where variables are refered to just using $varname rather than $this ->
varname
within classes.
Michael

Jul 17 '05 #14
Thanks Tony. I'm sure I'm being a bit thick here. I've only just started
attempting to write classes and I'm not sure why I'm finding them so
difficult.
Do you only declare with 'var = $varname' if it's a variable that you need
to have as a global within the class?
Mike

"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message
news:c8*******************@news.demon.co.uk...
If you refer to $varname within a class method then that variable is local
only to that method.

If you refer to $this->varname then that variable is global to any method
within the class.

--
Tony Marston
http://www.tonymarston.net
"Michael" <le*****@britishlibrary.net> wrote in message
news:c8**********@sparta.btinternet.com...
Doing with variables in classes is fairly simple: you have to use $this-> all the time.


That's one of the parts I'm confused about - clearly there are a lot of
instances
where variables are refered to just using $varname rather than $this ->
varname
within classes.
Michael


Jul 17 '05 #15
No. Just var $varname;
Take a look at http://www.tonymarston.co.uk/php-mys...seobjects.html
for a brief desciption on how to use classes in PHP.

--
Tony Marston

http://www.tonymarston.net
"Michael" <le*****@britishlibrary.net> wrote in message
news:c8**********@titan.btinternet.com...
Thanks Tony. I'm sure I'm being a bit thick here. I've only just started
attempting to write classes and I'm not sure why I'm finding them so
difficult.
Do you only declare with 'var = $varname' if it's a variable that you need
to have as a global within the class?
Mike

"Tony Marston" <to**@NOSPAM.demon.co.uk> wrote in message
news:c8*******************@news.demon.co.uk...
If you refer to $varname within a class method then that variable is local only to that method.

If you refer to $this->varname then that variable is global to any method within the class.

--
Tony Marston
http://www.tonymarston.net
"Michael" <le*****@britishlibrary.net> wrote in message
news:c8**********@sparta.btinternet.com...
> Doing with variables in classes is fairly simple: you have to use

$this->
> all the time.

That's one of the parts I'm confused about - clearly there are a lot of instances
where variables are refered to just using $varname rather than $this -> varname
within classes.
Michael



Jul 17 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: BCC | last post by:
Hi, I have a class with several member variables that should be initialized according to user input before an object is instantiated. Using a static variable is required here. But, I would...
4
by: Brad Kartchner | last post by:
I'm attempting to write a program with several child classes derived from a single parent class. The parent class has a couple of variables that need to be present in each of the child classes. ...
4
by: Bryan Green | last post by:
So I'm working on a project for a C# class I'm taking, where I need to keep some running totals via static variables. I need three classes for three different types of objects. The base class and...
17
by: Woody Splawn | last post by:
I am finding that time after time I have instances where I need to access information in a variable that is public. At the same time, the books I read say that one should not use public variables...
9
by: Justin Voelker | last post by:
I have a configuration file that contains the host, username, password, and database name required for any database connections. The config file runs through a few if/then/else statements to...
20
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
2
by: Nikolaus Rath | last post by:
Hello, I am really surprised that I am asking this question on the mailing list, but I really couldn't find it on python.org/doc. Why is there no proper way to protect an instance variable...
17
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline...
1
by: xamalek | last post by:
I was thinking that when you override a struct variable when you are subclassing the struct, then the variable in the new struct would stomp on the old one ... (i.e.) the parent variable (i) and...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.