Jump to content

Recommended Posts

I created a class (Users) which I would like to call an instance from in another class. However, I'm getting the error:

PHP Parse error: syntax error, unexpected T_NEW in C:\www\PHPTestProject\index.php on line 13

Here's the conflicting code:

[code]
    class Test {
        private $user = new User("geneanthony", "hea9671");
            
    }
[/code]

How can I call another class from a class. This wouldn't be an issue if it wasn't in a class.
Link to comment
https://forums.phpfreaks.com/topic/5009-how-can-i-call-a-class-from-a-class/
Share on other sites

[!--quoteo(post=355272:date=Mar 15 2006, 02:33 AM:name=keeB)--][div class=\'quotetop\']QUOTE(keeB @ Mar 15 2006, 02:33 AM) [snapback]355272[/snapback][/div][div class=\'quotemain\'][!--quotec--]
It works fine for me like this..
[code]
class fooooooo {
    public function bar($s1) {
        $foo = new bar($RAWR);
        $foo->method();
    }
}[/code]

To each their own [=
[/quote]

Keeb, yours isnt the same. In the other two examples, the variable is a member of the class. Your $foo is local to bar().
[!--quoteo(post=355275:date=Mar 15 2006, 08:37 AM:name=greycap)--][div class=\'quotetop\']QUOTE(greycap @ Mar 15 2006, 08:37 AM) [snapback]355275[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Keeb, yours isnt the same. In the other two examples, the variable is a member of the class. Your $foo is local to bar().
[/quote]

That is correct.. I was offering my alternative way to offer the same solution.. I cannot see the benefit, other than object sharing during method execution.. from making it a member of the class.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.