<?php
class test
{
function main()
{
return rand(1,10000);
}
}
echo $this->test->main();
?>
Thanks
Posted 13 May 2007 - 12:31 AM
<?php
class test
{
function main()
{
return rand(1,10000);
}
}
echo $this->test->main();
?>
Posted 13 May 2007 - 01:15 AM
$this->main();that is only used within the class as such
class test {
function main() {
$hello = "Hello World";
return $hello;
}
echo $this->main();
}
<?php include "file_with_class.php"; $temp = new test(); echo $temp->main(); ?>
Posted 13 May 2007 - 01:35 AM
Posted 13 May 2007 - 01:57 AM
class test {
function bar(){
return 'The bar() method.';
}
function main() {
echo $this->bar();
}
}
$obj = new test();
$obj->main();
Last i checked, all that a class definition could contain was function definitions, not calls to functions.Edited by rc69, 13 May 2007 - 02:01 AM.
Posted 14 May 2007 - 02:31 AM
<?php
class test
{
function main($text)
{
return (username?).": ".$text;
}
}
?>
<?php
include "test.php";
$temp = new test();
echo $temp->username->main('lalala');
?>
Edited by Mr. Jay, 14 May 2007 - 02:33 AM.
Posted 14 May 2007 - 12:11 PM
<?php
class test{
var $username;
function main($text){
return $this->username.": ".$text;
}
}
?>
But yes, you can do what you want, but i've never seen the need for objects within objects, so you'll have to figure out the class set up.<?php
class test{
function main($text){
return $this->name.": ".$text;
}
}
class temp{
var $username;
var $name;
function temp($name){
$this->name = $name;
$username = new test();
}
}
$temp = new temp('blah');
?>
Again, go to php.net if you have more questions. As it stands, i think you need a better understanding of OOP before messing around with it to much. Not that it is dangerous or anything, it is just that you don't always need to use OOP to accomplish what you want to do.
0 members, 1 guests, 0 anonymous users