Jump to content

Recommended Posts

Im trying to create a class for this project of mine.

 

This is what it looks like now

 

class myclass {
function myfunction(){	
}	
}

I use this like I should

$class = new myclass;
$class->myfunction();

I want to make a subfunction of "myfunction", so I can use it like this.

$class = new myclass;
$class->myfunction->subfunction();

 

How would I go about doing that ?

Link to comment
https://forums.phpfreaks.com/topic/155939-making-a-subfunction-in-a-class/
Share on other sites

No, then I would have to call it like this.

 

$class = new myclass;
$class->subfunction();

 

and not like this

$class = new myclass;
$class->myfunction->subfunction();

 

I have tried to do an extend class, and I cant call it through the function myfunction.

<?php
error_reporting(E_ALL);
class subClass {
public $test;

function __construct($test) {
	$this->test = $test;
}
public function subMethod( ) {
	echo $this->test;
}
}

class mainClass {
public $subClass;
public $foo;

function __construct( ) {
	$this->subClass = new subClass('hello');
}
}
$myClass = new mainClass;
$myClass->subClass->subMethod();
?>

Its basically making the variable subClass a new class, which allows access to its methods. Whats the purpose for this?

1. It looks really nice and easy to use for people who might not know alot about php.

2. I have alot of functions in the base class, and I want to extend them in categories.

 

Like this:

$administration->account->create($somevars);
$administration->account->downgrade($somevars);
$administration->account->ban($somevars);
$administration->account->delete($somevars);
$environment->announce->toplayer($somevars);
$environment->announce->toworld($somevars);

 

EDIT:

Much thanks for your help, works perfect.

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.