Archive

Posts Tagged ‘static’

Paamayim Nekudotayim In PHP

January 30th, 2009 No comments

What? Don’t worry, I can’t say it either. It is officially called the Scope Resolution Operator (but also just a double colon) and is used to reference static properties and functions of a class. It is also used to reference overridden functions of classes.

To reference a constant of a class you do something similar to the following.

class MyClass {
 const CONST_VALUE = 'A constant value';
}
 
echo MyClass::CONST_VALUE;

To call a static function or a parameter you need to include the word static in the function or parameter definition. You can then reference this function through the scope resolution operator.

class MyClass {
 public static $my_static = 'static var';
 
 public static function thisIsFunction() {
 
 }
}
 
echo MyClass::$my_static; // prints 'static var'
MyClass::thisIsFunction(); // calls thisIsFunction() in MyClass

You can also use the scope resolution operator to reference functions and parameters in parent classes. This is accomplished by using the parent operator. The following code has two class definitions, one of which basically exists to call the function from the parent.

class MyClass {
 public static $my_static = 'static var';
 
 public static function thisIsFunction() {
 
 }
}
 
class ChildClass extends MyClass{
 
 public static function childFunction() {
  parent::thisIsFunction();
 }
}
 
OtherClass::childFunction(); // calls childFunction() in MyClass

The call to the childFunction() function basically calls the function thisIsFunction() in the parent class. This is useful if you want to override the parent function, but still use most of the basic functionality. For example, the child class could take in a parameter, which it then formats or alters and passes this to the parent class.

Set An IP Address From The Command Prompt In Windows

November 19th, 2008 No comments

Rather than use the old connection properties dialog in Windows you can open up a command prompt and use the netsh to set up all sorts of network specific settings. The most useful part of this is that you can create a bat file that will allow you to quickly change your local IP address very quickly.

To see a list of the network connections available you can use the following command.

netsh interface show interface

This runs the netsh program, in the interface context, and shows the interfaces available. There are lots of other contexts to chose from, just type netsh and then ? to see a list of commands. If you type in netsh and hit enter key you will see the prompt change to netsh meaning that you are in that program mode. Just type exit or bye to exit.

You can also ask for information about individual interfaces by using the name parameter.

netsh interface show interface name="Local Area Connection"

To inform a network interface that you want to change its IP address you need to call it by the network alias. Local Area Connection is usually the default, but if you have more than one network port (wired or wireless) then you should double check this.

To set the IP address of a network alias to run DHCP use the following.

netsh interface ip set address "Local Area Connection" dhcp

To set the IP address manually use the following.

netsh interface ip set address "Local Area Connection" static 192.168.0.10 255.255.255.0 192.168.0.1 1

The static parameter needs three items. The IP that the connection is to be set to, the network mask and the gateway.

In this way, if you travel a lot and want to turn on or off DHCP at the touch of a button then you can create a series of bat files that use these commands.

Categories: DOS Tags: , , , , , , , , , ,