Jump to content

Need help with class?


 Share

Go to solution Solved by requinix,

Recommended Posts

Posted (edited)

Hi, I'm new here! So I'm trying to create a class & I need to grab the title of my program through `get_appTitle ( )`  whose data is changed by `__InitializeData ( )`

How can I do that?

<?php
class MainframeData {
	public $appTitle;
	public $appName = "App Name";
	public $version = "1.0";
	public $verPrefix = "";

	function __construct ( ...$params ) {
		$this -> param = $params;
	}

	function get_appTitle ( ) {
		return $this -> appTitle;
	}

	function __InitializeData ( ) {

		if ( $this -> verPrefix !== "" && empty ( $this -> verPrefix ) === false ) {
			$this -> appVer = ( $this -> version . " { " . $this -> verPrefix . " } " );
			$this -> appTitle = $appName . " - " . "Version" . " " . $appVer;
		}

		if ( $this -> verPrefix !== "" || empty ( $this -> verPrefix ) === true ) {
			$this -> appVer = $this -> version;
			$this -> appTitle = $this -> appName . " - " . " { " . "Version" . " " . $this -> appVer . " } ";
		}
	}
}

$mfrdata = new MainframeData ( );
$mfrdata -> __InitializeData ( );

?>

Any help is GREATLY appreciated!

 

 

 

Edited by AquariaXI
Link to comment
Share on other sites

Posted (edited)

It is written on index.php which is separate but here it is

<?php $mfrdata = new MainframeData ( ); ?>
<h1><?php echo "AppTitle :: " . $mfrdata -> get_appTitle ( ); ?></h1><br>
<hr><br>
	
Edited by AquariaXI
Link to comment
Share on other sites

You already know that the appTitle is set by InitializeData. If you don't call InitializeData then there will be no appTitle.

All that InitializeData code should exist in the constructor anyways. Move it and you won't have to call any special methods before you can use appTitle.

Link to comment
Share on other sites

  • Solution

All that code in InitializeData should be inside the constructor instead. There is no need for InitializeData to exist. It forces you to call that method every time you create a new instance of MainframeData, and if you forget then you get problems like the one that started this thread.
If you need to set up appVer and appTitle when the object is created then you should be literally setting up appVer and appTitle when the object is created.

  • Like 1
Link to comment
Share on other sites

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.

 Share

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