Jump to content

Archived

This topic is now archived and is closed to further replies.

pedrobcabral

oop question

Recommended Posts

I'm getting stucked with the following:

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

$myclass = new something(input_here_for_my_var);
?>
[/code]

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.

Share this post


Link to post
Share on other sites
[code=php:0]
class something {
  var $var;
  function __construct($in) {
    $this->var = $in;
  }
}
[/code]

Share this post


Link to post
Share on other sites
One comment, you seem to mixing versions

__construct is php5
var is php4

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

$myclass = new something5('hello');
echo $myclass->var;
?>[/code]

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

$myclass = new something4('world');
echo $myclass->var;
?>[/code]

Share this post


Link to post
Share on other sites

×

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.