Jump to content

oop question


pedrobcabral

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.
Link to comment
https://forums.phpfreaks.com/topic/22179-oop-question/
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]
Link to comment
https://forums.phpfreaks.com/topic/22179-oop-question/#findComment-99315
Share on other sites

Archived

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

×
×
  • 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.