News Register Control Panel Private Messages Members List Team Search News Posts About Us

Linux Advisory » Q & A - Discussions » Programming & Coding » Help, need a little help!!! » Hello Guest [login|register]
Last Post | First Unread Post Print Page | Recommend to Friend | Add Thread to Favorites
Post New Thread Post Reply
Author
Post « Previous Thread | Next Thread »
xception xception is a Male
Cool Newbie


Registration Date: 05-27-2003
Posts: 23
Location: Eire
Linux Distro: Mandrake

Rating:
2 Votes - Average Rating: 7.50

Level: 13 [?]
Experience Points: 3.368
Next Level: 4.033
665 point(s) of experience needed for next level

OFFLINE

Question Help, need a little help!!! Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

Well I've started to play about with PHP and I'm quiet ashamed to say that I'm already stuck Frown

I don't seem to be able to call a function from a constructor for some reason.

I want to do something like this:
php:
class User
{
    function 
User($fName$lName$email)
    {
        if( 
userExists($fName$lName$email) )
        {
            
//user already exists
        
}
        else...

    }

    function 
userExists($fNamelName$email)
    {
        
//check for user

        
return bool;
    }
}


and from another page I do the following

$user = new User('Jimbo', 'Jones', '[email protected]');

but I'm getting an error like so:
Fatal error: Call to undefined function: userExists()

Why cant i call a function from a constructor?



verum ipsum factum

06-09-2003 23:48 Send an Email to xception Search for Posts by xception Add xception to your Buddy List
xception xception is a Male
Cool Newbie


Registration Date: 05-27-2003
Posts: 23
Location: Eire
Linux Distro: Mandrake

Rating:
2 Votes - Average Rating: 7.50

Level: 13 [?]
Experience Points: 3.368
Next Level: 4.033
665 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

Hey, i figured it out. No need to reply to this post. Thanks



verum ipsum factum

06-10-2003 12:33 Send an Email to xception Search for Posts by xception Add xception to your Buddy List
Ravish Ravish is a Male
Administrator




Registration Date: 12-27-2002
Posts: 694
Location: Internet
Linux Distro: Redhat, Mandrake, Gentoo

Rating:
15 Votes - Average Rating: 8.13

Level: 29 [?]
Experience Points: 206.635
Next Level: 242.754
36.119 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

I think you would also post the solution that you tried over here. So that other users could get some knowledge.



06-10-2003 12:50 Send an Email to Ravish Homepage of Ravish Search for Posts by Ravish Add Ravish to your Buddy List AIM Screenname: Ravi5h YIM Screenname: ravishahuja1
xception xception is a Male
Cool Newbie


Registration Date: 05-27-2003
Posts: 23
Location: Eire
Linux Distro: Mandrake

Rating:
2 Votes - Average Rating: 7.50

Level: 13 [?]
Experience Points: 3.368
Next Level: 4.033
665 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

Sorry about that. How rude of me Smile

The solution is like so:

if( $this->userExists($fName, $lName, $email) )
{
//user already exists
}

Notice ' $this->' before the function name. I'm not 100% sure why It's needed. I suppose it's letting the PHP engine know that userExists(...) is a function in this class. If anybody knows for sure why this is needed could they post it here. I would like to find out more about '$this'.

Cheers



verum ipsum factum

06-10-2003 16:01 Send an Email to xception Search for Posts by xception Add xception to your Buddy List
Telos Telos is a Male
Super Moderator


Registration Date: 06-04-2003
Posts: 129
Location: Finland
Linux Distro: hmm....

Rating:
3 Votes - Average Rating: 7.00

Level: 19 [?]
Experience Points: 17.884
Next Level: 22.851
4.967 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

yes, it's needed because you are referring to that instance of the class and not anywhere else...working with classess need that $this -> so they know what you are referring to...don't know if I explained it correctly but that's how I know it.



06-10-2003 16:19 Send an Email to Telos Homepage of Telos Search for Posts by Telos Add Telos to your Buddy List Add Telos to your Contact List AIM Screenname: dreamimpactcom
Heather Heather is a Female
Respected Member




Registration Date: 05-21-2003
Posts: 511
Location: Lost City of Zen.
Linux Distro: I'm OS neutral.

Rating:
9 Votes - Average Rating: 3.67

Level: 24 [?]
Experience Points: 77.745
Next Level: 79.247
1.502 point(s) of experience needed for next level

OFFLINE

Post Reply with Quote Edit/Delete Post Report Post to a Moderator       IP Information

Dang...I wanted to help him...ya'll suck! Tongue



Utinam logica falsa tuam philosophiam totam suffodiant

06-11-2003 06:33 Send an Email to Heather Search for Posts by Heather Add Heather to your Buddy List
Post Reply:
Title (Optional):
Message:


Convert URLs: Automatically converts internet addresses into links by adding [url] and [/url] around them.
Email Notification: Notifies you by email every time there is a new post in this thread.
Deactivate smilies in this post.
Add Signature: Displays your signature in this post.


Tree Structure | Board Structure
Post New Thread Post Reply
Go to:


Powered by Burning Board 2.0.2 © 2001-2002 WoltLab GbR
English Translation by Satelk