Skip to content

Instantly share code, notes, and snippets.

@shahariaazam
Created August 16, 2014 17:04
Show Gist options
  • Select an option

  • Save shahariaazam/0f92253149fbe0a55122 to your computer and use it in GitHub Desktop.

Select an option

Save shahariaazam/0f92253149fbe0a55122 to your computer and use it in GitHub Desktop.
<?php
class MDC_IpManagerClass{
public $MyIp = $_SERVER['REMOTE_ADDR'];
//...................................................
// more code snippet
//...................................................
}
/**
* Here $MyIp is just a class property declaration. It can't holds any EXPRESSION.
*
* $_SERVER['REMOTE_ADDR'] is an expression.
*
* If you want to assign that expression to that property. You have to do that in that class constructor.
* See the following snippet.
*/
class MDC_IpManagerClass{
public $MyIp;
public function __construct()
{
$this->MyIp = $_SERVER['REMOTE_ADDR'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment