Problem With Constructor Function

This is a discussion on Problem With Constructor Function within the PHP Language forums, part of the PHP Programming Forums category; Hello, I have a nice, simple mySQL abstraction layer I have worked out in PHP. Recently I realized on a ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-20-2005
jerrygarciuh
 
Posts: n/a
Default Problem With Constructor Function

Hello,

I have a nice, simple mySQL abstraction layer I have worked out in PHP.
Recently I realized on a project that I wanted one of my objects to
automatically clean-up its table on creation. I had been instantiating a
News object in a page and then calling $newsObj->cleanUp();

So I changed the name of cleanUp() to News(). Seems simple enough right?
Now it should clean up on instantiation...

class News extends DBI {
var $table = 'news';

function cleanUp() {
$data = array(
"endDate != '0000-00-00'",
"endDate < NOW()"
);
$this->delete($data);
}
}

However, the constructor function did not have access to the $dbh inherited
from the parent and threw the appropriate errors:

Warning: mysql_query(): Access denied for user: 'talking@localhost' (Using
password: NO) in /yata/yata/yata/classDBI.php on line 211

So my question to you, without much code to go on, is whether anyone knows
why this would be? When I dumped $this it held what I would expect and was
the Object type it should be.

Thanks for any advice!!

jg




Reply With Quote
  #2 (permalink)  
Old 02-20-2005
Peter Fox
 
Posts: n/a
Default Re: Problem With Constructor Function

Following on from jerrygarciuh's message. . .
>However, the constructor function did not have access to the $dbh inherited
>from the parent and threw the appropriate errors:
>

Somewhere in the manual it says you need to explicitly call parent
constructors. eg parent::ClassFoo() as 1st line in your constructor
function.

--
PETER FOX Not the same since the deckchair business folded
peterfox@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>
Reply With Quote
  #3 (permalink)  
Old 02-20-2005
jerrygarciuh
 
Posts: n/a
Default Re: Problem With Constructor Function

Thanks Peter!!

jg


"Peter Fox" <peterfox@eminent.demon.co.uk.not.this.bit.no.html > wrote in
message news:ox$qpJAbNFGCFw1w@eminent.demon.co.uk...
> Following on from jerrygarciuh's message. . .
>>However, the constructor function did not have access to the $dbh
>>inherited
>>from the parent and threw the appropriate errors:
>>

> Somewhere in the manual it says you need to explicitly call parent
> constructors. eg parent::ClassFoo() as 1st line in your constructor
> function.
>
> --
> PETER FOX Not the same since the deckchair business folded
> peterfox@eminent.demon.co.uk.not.this.bit.no.html
> 2 Tees Close, Witham, Essex.
> Gravity beer in Essex <http://www.eminent.demon.co.uk>



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:39 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0