another argument passing problem :-(

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andy

    another argument passing problem :-(

    Hi all,

    Sorry to present you all with another boring problem but I've spent
    all day trying to get this to work with no success.

    Below is a function to which I pass the argument &$myCell (which is an
    instance of my class "Cell"). I am not sure whether it is necessary
    or desirable to use the '&' and I've noticed that this subject seems
    to be a source of considerable debate in this group (is this the
    method used implicitly in java?).

    My problem here is that the lines;

    $html .= $newCell->getAttributes( );
    $html .= $newCell->getData();

    do not work. They refer to functions within the Cell class but the
    error that comes up is;

    Fatal error: Call to a member function on a non-object


    function addCell(&$myCel l)
    {
    $html="<td>";
    $html .= $newCell->getAttributes( );
    $html .= $newCell->getData();

    return $html .= "</td>";
    }


    If it should help in identifying the problem, the remainder of this
    class is printed below. Thanks for your help ;-)

    Andy

    --------------------------------------------------------------------------
    //test data
    $testTable = new Table('border=" 1" summary="Test table"');
    $c1 = new Cell("skdj", "bgsdlr");
    $c2 = new Cell('jzhb', 'sjbvf');
    $c3 = new Cell('zjskdbv', 'jsdbsjkv');
    $c4 = new Cell('jzsdcg', 'zkdjbd');
    $r1 = array($c1, $c2);
    $r2 = array($c3, $c4);
    $testTable->startTable() ;
    $testTable->addRow($r1);
    $testTable->addRow($r2);
    $testTable->stopTable();

    //Table Class
    class Table
    {
    var $attributes;


    function Table($attribut es="")
    {
    $this->attributes = $attributes;
    }


    function startTable()
    {
    echo $html = "<table " .$this->attributes . "\n";
    }


    function stopTable()
    {
    echo $html = "</table>";
    }


    function addRow($newRow)
    {
    $html="<tr>";
    for( $i ; $i < count($newRow) ; $i++ )
    {
    $cells=$newRow[i];
    $html .=$this->addCell($cells );
    }
    echo $html .="</tr>";
    }
    }
    ?>
  • Pedro Graca

    #2
    Re: another argument passing problem :-(

    Andy wrote:
    (snip)[color=blue]
    > Fatal error: Call to a member function on a non-object
    >
    >
    > function addCell(&$myCel l)
    > {
    > $html="<td>";
    > $html .= $newCell->getAttributes( );[/color]

    Where does $newCell come from? :)
    [color=blue]
    > $html .= $newCell->getData();
    >
    > return $html .= "</td>";
    > }[/color]

    Turn on error reporting for PHP and it will tell you when you use
    unintialized variables.

    Insert

    error_reporting (E_ALL);
    ini_set('displa y_errors', '1');

    at the top of your scripts (or change php.ini)



    --
    USENET would be a better place if everybody read: : mail address :
    http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
    http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
    http://www.expita.com/nomime.html : to 10K bytes :

    Comment

    • Chung Leong

      #3
      Re: another argument passing problem :-(

      The solution is:

      <table>
      <tr>
      <td>Pluralita s non est ponenda sine neccesitate</td>
      </tr>
      </table>

      "Andy" <andyfaeglasgow @yahoo.co.uk> wrote in message
      news:b252a1fa.0 404010737.11193 ad8@posting.goo gle.com...[color=blue]
      > Hi all,
      >
      > Sorry to present you all with another boring problem but I've spent
      > all day trying to get this to work with no success.
      >
      > Below is a function to which I pass the argument &$myCell (which is an
      > instance of my class "Cell"). I am not sure whether it is necessary
      > or desirable to use the '&' and I've noticed that this subject seems
      > to be a source of considerable debate in this group (is this the
      > method used implicitly in java?).
      >
      > My problem here is that the lines;
      >
      > $html .= $newCell->getAttributes( );
      > $html .= $newCell->getData();
      >
      > do not work. They refer to functions within the Cell class but the
      > error that comes up is;
      >
      > Fatal error: Call to a member function on a non-object
      >
      >
      > function addCell(&$myCel l)
      > {
      > $html="<td>";
      > $html .= $newCell->getAttributes( );
      > $html .= $newCell->getData();
      >
      > return $html .= "</td>";
      > }
      >
      >
      > If it should help in identifying the problem, the remainder of this
      > class is printed below. Thanks for your help ;-)
      >
      > Andy
      >
      > --------------------------------------------------------------------------
      > //test data
      > $testTable = new Table('border=" 1" summary="Test table"');
      > $c1 = new Cell("skdj", "bgsdlr");
      > $c2 = new Cell('jzhb', 'sjbvf');
      > $c3 = new Cell('zjskdbv', 'jsdbsjkv');
      > $c4 = new Cell('jzsdcg', 'zkdjbd');
      > $r1 = array($c1, $c2);
      > $r2 = array($c3, $c4);
      > $testTable->startTable() ;
      > $testTable->addRow($r1);
      > $testTable->addRow($r2);
      > $testTable->stopTable();
      >
      > //Table Class
      > class Table
      > {
      > var $attributes;
      >
      >
      > function Table($attribut es="")
      > {
      > $this->attributes = $attributes;
      > }
      >
      >
      > function startTable()
      > {
      > echo $html = "<table " .$this->attributes . "\n";
      > }
      >
      >
      > function stopTable()
      > {
      > echo $html = "</table>";
      > }
      >
      >
      > function addRow($newRow)
      > {
      > $html="<tr>";
      > for( $i ; $i < count($newRow) ; $i++ )
      > {
      > $cells=$newRow[i];
      > $html .=$this->addCell($cells );
      > }
      > echo $html .="</tr>";
      > }
      > }
      > ?>[/color]


      Comment

      Working...