How to write php code is beautiful. this is an old problem. The appearance of classes in php5 makes php logic and writing a level. However, php code such as queries still shows a process-style "garbled" image. In particular, php does not require var variables, and anonymous functions are not perfect. In general, writing such code lacks aesthetics. If I write JavaScript code like this, :( & nbsp php code is beautiful
This is an old problem. The appearance of classes in php5 makes php logic and writing a level. However, php code such as queries still shows a process-style "garbled" image. In particular, php does not require var variables, and anonymous functions are not perfect. In general, writing such code lacks aesthetics.
If I write js like this:
( function(w) {
var a = 1,
b= 2,
fun = function() {
return a + b;
};
w.onload = function(){
fun();
}
})(window);
In this way, variables and the executed code are separated easily. However, php is much more messy:
$a = 1;
$b = 2;
function fun() {
global $a;
global $b;
return $a + $b;
}
foreach($_GET as $key=>$val) {
$$key = urldecode($val);
}
if((int)$getVal > 1) {
...
} else {
...
}
$val = null;
$arr = array();
foreach($getArr as $val) {
if(strlen($val) > 0) {
$arr[] = $val;
}
}
echo fun(),implode('-',$arr);
exit;
The more you write it down, the more you can't read it...
Read discuz! Write xplus, which uses a lot of functions and class packaging. However, some php code for judging and querying is still procedural. I really want to know how everyone writes php code at ordinary times ?! Let's talk about it, especially for coders who have written. net and jsp! Php writing
------ Solution --------------------
Three letters: OOP
Encapsulate CLASS, JAVA requires full OOP, so his code looks pretty