Jump to content


Photo

oop question


  • Please log in to reply
2 replies to this topic

#1 pedrobcabral

pedrobcabral
  • Members
  • PipPipPip
  • Advanced Member
  • 108 posts

Posted 26 September 2006 - 11:02 PM

I'm getting stucked with the following:

<?php
class something {
var $var;
__construct($input) {
$this->var = $input;
}
}

$myclass = new something(input_here_for_my_var);
?>

Now imagine that i want to have my var set to "hello". How can I make the call? Doing $myclass(var) does not work.

Thanks for your help,
P.B.C.

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 26 September 2006 - 11:35 PM

class something {
  var $var;
  function __construct($in) {
    $this->var = $in;
  }
}


#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 26 September 2006 - 11:37 PM

One comment, you seem to mixing versions

__construct is php5
var is php4

<?php   //v 5
class something5 {
    public $var;
    
    function __construct($input) {
        $this->var = $input;
    }
}

$myclass = new something5('hello');
echo $myclass->var;
?>

<?php   //v 4
class something4 {
    var $var;
    
    function something4($input) {
        $this->var = $input;
    }
}

$myclass = new something4('world');
echo $myclass->var;
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users