1) Function example
php: function inc($val)
{ return $val + 1;}
A procedure is also a function, but it has no return value.
jscript, javascript:
function inc(val)
{ return val + 1;}
The definition of process is the same as above.
VBScript:
function inc(val)
inc = val + 1
end function
procedure
sub inc2(byref val)
val = val + 1
end sub
2) Class example
php:
class parent {
var property;
function parent() { }
function method() { }
}
/* Inheritance */
class child extends parent { var property= new value;
}
jscript or javascript:
class parent {
property=value
function parent() function method() { } }
Inheritance is not supported (this is the original text, but it seems to be supported now)
vbscript:
Classes are not supported ((this is the original text, but it is also supported now)
3) Scope of variables
php: Variables defined outside functions or classes are allowed to be global variables; local variables can also be defined within functions and classes.
Unlike other languages, when using variables, you must declare a global variable using the keyword global in functions and classes.
$globalvar = 1;
function show_global( ) {
global $globalvar;
print $globalvar;
}
jscript or javascript:
Similar to PHP, no need to declare global variables in functions.
vbscript:
Similar to PHP, in functions and There is no need to declare global variables during the process.
4) Access reference
php: Use keywords in function parameters
jscript or javascript
Simple access through variables, reference complex types in functions
vbscript:
Use ByRef keyword in Sub or function parameters.
5) Default parameters
php: supports function A(param1="abc")
Others are not supported.
6) Reference return (don’t know how to translate)
php:function getarray123() {
$val = array(1,2,3);
return & $val;
}
Then use
$val = &getarray123();
Others are not supported
7) Category
php: better supported
Others: average
8) Error handling
php: Use @ to prevent running errors.
$val = @function_can_fail();
@scope is the current declaration, the last error can be checked in $php_errormsg if you set track_errors=On in PHP.ini.
javascript or jscript:
Use try and catch.
try {
function_can_fail()
} catch(err) { Response.Write(err)
}
vbscript:
Use On Error Resume Next to ignore running errors
New The version also supports try and catch
In addition, there is also an article about language comparison, which you can translate if you are interested.