views:

55

answers:

2

Please stop me if i am doing something wrong. It works but somehow it doesn't appear the right way to me... Look at the member function call in talks.php. Does this look right to you? Is there a better way to solve that? Thanks.

show.php

I am passing my user class by reference:

$talks = new talks($comments, $user);

talks.php:

[...]  
function __construct($comments, &$user)  
{  
    //Passing user class  
    $this->user = $user;  

    [...]  
    if ($this->user->is_loaded()){}
+1  A: 

This looks a-ok to me. What problem do you see with it?

Myles
If you say it's ok i am glad... I just never have used it that way (i am still quite a wannabe programmer).. and didnt trust what i've written evn if it worked. Thank You!!!
Booosh
+1  A: 

In php 5, objects are always passed by reference.
From http://www.php.net/manual/en/language.oop5.references.php:

A PHP reference is an alias, which allows two different variables to write to the same value. As of PHP5, an object variable doesn't contain the object itself as value anymore. It only contains an object identifier which allows object accessors to find the actual object. When an object is sent by argument, returned or assigned to another variable, the different variables are not aliases: they hold a copy of the identifier, which points to the same object.

So, you should not need the "&" operator in the parameter list of your constructor.

Davide Gualano
Doesn't hurt anything to be explicit though.
Myles