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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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