PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old October 6th, 2003, 05:32 PM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 5
Problems with PHP OOP

Ok, i am attempting to write a class to deal with mysql database actions, however i am having difficaulty with some of the classes local variables - they appear to be converted to resources
PHP Code:
 example code:
class 
myclass
{
  var 
$host;
  var 
$user;
  var 
$password;
  var 
$db_name;
  var 
$connect_id;

  
// Constructor
  
function myclass$host$username$password )
  {
    
$this->$host $host;
    
$this->$user $username;
    
$this->$password $password;
    
$this->$db_name='';
    
$this->$connect_id='';

    if ( 
$this->$connect_id mysql_connect$host$username$password ) )
    {
      return 
TRUE;
    }
    else
    {
      return 
FALSE;
    }
  } 

Before the if statement, ie before mysql_connect is called, the local variables are as you would expect, host, user, password all equal the parameter passed, db_name and connect_id are blank, and after mysql_connect they are all 'Resource id #1'.
As far as i can see the classes local vars should not be affected at all, save $connection_id. This is annoying as other functions may need to access these variables later.
Does anyone know why this happens, or how to stop it. (or indeed, how to access the values instead of 'resource id #1')
Cheers

Last edited by mattp23 : October 6th, 2003 at 05:42 PM.

Reply With Quote
  #2  
Old October 7th, 2003, 07:10 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Could have something to do with extra dollar signs. When you declare your member vars at the top of the class, you need the dollar signs, When you use them with $this->, you don't. So when you're using $this->$host, you should use $this->host. Could be that the dollar sign makes the class think you're asking for a reference to the last var set or something like that. Anyway, try removing the extra dollar signs and see if that works out.

Reply With Quote
  #3  
Old October 7th, 2003, 07:55 AM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 5
thank you, that would appear to be the problem

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Problems with PHP OOP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway