About Abstract Classes:
Abstract class car{
Abstract function getmaximumspeed ();
}
Class Fastcar extends car{
function Getmaximumspeed () {
return 150;
}
}
Precautions:
If the implemented class is also abstract, you do not have to implement all of its methods.
$street->addcar (New Fastcar ());
-------------------------
Interface: Interface implements
An abstract class is used when there is a logical hierarchical relationship between a parent class and a subclass.
A particular interaction behavior between two or more objects that differ significantly from each other, with interfaces.
Interface
Using interfaces, you can specify that a class must implement those methods, but you do not need to define the specifics of these methods, we can define an interface through interface, just like defining a standard class, but all of the methods defined in it are empty, and all methods defined in the interface must be public
Implement an interface, you can use the implement operator, the class must implement the method defined in the interface, if you implement multiple interfaces, you can use commas to split the names of multiple interfaces
Attention
When implementing multiple interfaces, the methods in the interface cannot have duplicate names
Interfaces can also be inherited by using the extends operator
Interfaces can be defined constants, interface constants and class constants are used exactly the same, they are fixed value, not quilt class or sub-interface modification
Example:
//Declaration Interface
Interface itemplate{
Public Function setvariable ($name, $var);
Public Function gethtml ($template) ;
}
//Implement Interface
Class Template implements itemplate{
Private $vars =array ();
Public Function setvariable ($ Name, $var) {
$this->vars[$name]= $var;
}
Public Function gethtml ($template) {
foreach ($this->vars as $names = + $value) {
$template =str_replace ( ' {'. $names. '} ', $value, $template);
}
return $template;
}
}
Example 2:
Interface a{
Public function foo ();
}
Interface b{
Public function Bar ();
}
//Inherit interface
Interface C extends a,b{
Public function baz ();
}
//Implement Interface
Class D implements c{
Public Function foo () {
}
Public Function bar () {
}
P ublic function Baz () {
}
}
Interface a{
Const b= "Hello";
}
Abstract class
PHP5 supports abstract classes and abstract methods. An abstract class cannot be instantiated directly, it must inherit the abstract class, and then instantiate the subclass, any class, if at least one of the methods in him is declared abstract, then the class must be declared abstract, if the class method is declared abstract, then it cannot include the specific function implementation
When inheriting an abstract class, the subclass must implement all the abstract methods in the abstract class, and the visibility of these methods must be the same (or more easily) as in the abstract class, if an abstract method in the abstract class is declared as protected, Then the methods implemented in the subclass should be declared as protected or public
Example:
Abstract class abstractclass{
Abstract methods
Abstract protected function getValue ();
Abstract protected function Prefievalue ($p);
Common methods (non-abstract methods)
Public Function PrintOut () {
Print $this->getvalue ();
}
}
Class ConcreteClass1 extends abstractclass{
protected function GetValue () {
return "ConcreteClass1";
}
Public Function Prefievalue ($p) {
Return "{$p}concreteclass1";
}
}
Class ConcreteClass2 extends abstractclass{
protected function GetValue () {
return "ConcreteClass2";
}
Public Function Prefievalue ($p) {
Return "{$p}concreteclass2";
}
}
$class 1=new ConcreteClass1 ();
$class 1->printout ();
echo $class 1->prefievalue (' Foo_ ');
/*
Print Result: ConcreteClass1
Foo_concreteclass1
2. Class constants that call static methods that are still feasible for abstract classes are not allowed
Abstract class Foo
{Const a= "Hello";
static function bar ()
{
echo "test\n";
}
}
foo::a;//No output
Foo::bar ();//test
----------------------------
$original = Array (' key ' = ' value ', ' key2 ' = ' value2 ');
$json = Json_encode ($original);
$restored =j Son_decode ($json);
JSON and JavaScript
The first thing to do is download json.js
function Showjsondata () {
Original = new Array (0,1,2,3);
JSON = original.tojsonstring ();
...
}
Json.parsejson () [0]
Suggest.html:
<script src= "json.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >
var XHR;
function Getxhr () {
var req;
if (window. XMLHttpRequest) {
req = new XMLHttpRequest ();
}else{
req = new ActiveXObject ("Microsoft.XMLHTTP");
}
return req;
}
function suggest () {
if (xhr && xhr.readstate!=0) {
Xhr.abort ();
}
XHR = GETXHR ();
Xhr.open ("POST", "http://example.com/suggest.php", true);
}
</script>
-------------------------------
thinkphp
If you change the project directory (for example, change application to apps), you only need to alter the APP_PATH constant definition in the portal file:
Define (' App_path ', './apps/');
Require './thinkphp/thinkphp.php ';
After updating or environment change, the first problem is emptying the runtime directory;
1105PHP Notes 001