Jump to content

Class Variable Scope


hmvrulz

Recommended Posts

<?php

/**
*
* @project Framework
*
* @author Harsha M V
* @copyright 2008
* 
*/

//print_r($scriptName);


class url_interpreter
{
	public $id;
	public $module;
	public $action;
	public $mobile;
	public $path;

	function __constructor()
	{
			// Exploding the Components of the Request URL and making an Array of the Components
			$requestURI = explode('/', $_SERVER['REQUEST_URI']);

			// Exploding the Components of the Script (index.php) and making an Array of the Components
			$scriptName = explode('/', $_SERVER['SCRIPT_NAME']);

			// Unsetting Array the matches after Matching Script and URL Array
			for ($i = 0; $i < sizeof($scriptName); $i++) {
					// Matching Array Components
					if ($requestURI[$i] == $scriptName[$i]) {
							// Unsetting Array if theres a Match
							unset($requestURI[$i]);

					}
			}

			// Reseting Array Keys
			$path = array_values($requestURI);
			//print_r($this->$path);
			return $path;

	}


}
$hd = new url_interpreter;

print_r($hd);



?>

 

 

OUTPUT

 

url_interpreter Object
(
    [id] => 
    [module] => 
    [action] => 
    [mobile] => 
    [path] => 
)

 

When i go to localhost/users/show/11/mobile

 

it should show

url_interpreter Object
(
    [id] => 11
    [module] => users
    [action] => show
    [mobile] => 1
    [path] => 
)

how to make the variables

 

mobule, action and id be available globally. Am getting Confused with the Variable scope. I tried going thru a tutorial also...:mad:

Link to comment
https://forums.phpfreaks.com/topic/129064-class-variable-scope/
Share on other sites

I don't see where id, module, action, mobile are given any values in the constructor.

 

$path is set but this refers to a local value inside the function. You need $this->path to refer to the object variable.

 

Your constructor function name should be "__construct()" . It isn't called at present. Don't return $path from the function.

Link to comment
https://forums.phpfreaks.com/topic/129064-class-variable-scope/#findComment-669152
Share on other sites

I don't see where id, module, action, mobile are given any values in the constructor.

 

$path is set but this refers to a local value inside the function. You need $this->path to refer to the object variable.

 

Your constructor function name should be "__construct()" . It isn't called at present. Don't return $path from the function.

 

BLOOPER.. Thanx

Link to comment
https://forums.phpfreaks.com/topic/129064-class-variable-scope/#findComment-669180
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.