0

Hello,
I am looking for a way to stop variable scope leakage.

I have a class with a function to include a page something like this:

class functions{

function getView($viewTheme, $viewType, $viewTask, $viewFunction, $pageID=null, $itemID=null){
$baseView = ROOTME.DIR_VIEWS.$viewType.'/'.$viewTheme.'/'.BASE_VIEW_DIR.$viewTask.'/'.$viewFunction.'.php';

if(file_exists($baseView)){
include($baseView);	
}

}

}

My problem is, I am now wanting to reuse this function in some of the pages multiple times include, but the variables $viewTheme, $viewType, $viewTask, $viewFunction, $pageID, $itemID are needed again after the next call of the function, and they are overwritten by the next call of the function.

Is there a way to prevent this? For example make variables stay inside the function call and and only usable by the file it includes - and if that calls the function again, it again has its own variables?

Kind regards, and thanks in advance!

Edited by OnIIcE: n/a

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by pritaeas
0

I'd make them properties. Then you can set them as you like, you can remove them from the function call, and they are still accessible after your first call.

0

Hi,
thanks for the response.

Would that be like making properties in the class? (e.g $this->viewTheme) ?
If so wouldn't they just be overwritten when the functions called again?

thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.