PHP, JScript 和 VBScript 函数和类的语法_PHP
VBScript
1)函数的例子
php: function inc($val)
{ return $val + 1;}
过程也是个函数,只不过没有返回值。
jscript, javascript:
function inc(val)
{ return val + 1;}
过程的定义同上。
VBScript:
function inc(val)
inc = val + 1
end function
procedure
sub inc2(byref val)
val = val + 1
end sub
2)类的例子
php:
class parent {
var property;
function parent() { }
function method() { }
}
/* 继承 */
class child extends parent { var property= new value ;
}
jscript or javascript:
class parent {
property=value
function parent() function method() { } }
不支持继承(原文是这样,但好像现在也支持了)
vbscript:
不支持类((原文是这样,但现在也支持了)
3)变量的范围
php:变量在函数或类外定义是允许的是全局变量;也可以在函数和类中定义局部变量。
不像其它的语言,在使用变量时,你必须声名一个全局变量在函数和类中使用关键字global.
$globalvar = 1;
function show_global( ) {
global $globalvar;
print $globalvar;
}
jscript or javascript:
类似PHP, 在函数中不需声明全局变量.
vbscript:
类似PHP, 在函数和过程中不需声明全局变量.
4)访问引用
php:使用关键字,在函数的参数中
jscript or javascript
简单的通过变量访问,在函数里引用复杂的类型
vbscript:
使用ByRef 关键字在Sub 或函数的参数中.
5)默认参数
php:支持function A(param1="abc")
其它的不支持。
6)引用返回(不知如何翻)
php:function getarray123() {
$val = array(1,2,3);
return & $val;
}
然后在代码中使用
$val = &getarray123();
其它的不支持
7)类
php:支持的较好
其它的:一般
8)错误处理
php:使用@ 防止运行错误.
$val = @function_can_fail();
@范围是当前的声明,最后的错误能够在$php_errormsg检查出来,如果你设置了track_errors=On 在PHP.ini.
javascript or jscript:
使用try and catch.
try {
function_can_fail()
} catch(err) { Response.Write(err)
}
vbscript:
使用On Error Resume Next 忽略运行错误
新的版本也支持try 和 catch
另外,还有一篇关于语言的比较,有兴趣的也可以翻译一下。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

Go language provides two dynamic function creation technologies: closure and reflection. closures allow access to variables within the closure scope, and reflection can create new functions using the FuncOf function. These technologies are useful in customizing HTTP routers, implementing highly customizable systems, and building pluggable components.

In C++ function naming, it is crucial to consider parameter order to improve readability, reduce errors, and facilitate refactoring. Common parameter order conventions include: action-object, object-action, semantic meaning, and standard library compliance. The optimal order depends on the purpose of the function, parameter types, potential confusion, and language conventions.

The key to writing efficient and maintainable Java functions is: keep it simple. Use meaningful naming. Handle special situations. Use appropriate visibility.

1. The SUM function is used to sum the numbers in a column or a group of cells, for example: =SUM(A1:J10). 2. The AVERAGE function is used to calculate the average of the numbers in a column or a group of cells, for example: =AVERAGE(A1:A10). 3. COUNT function, used to count the number of numbers or text in a column or a group of cells, for example: =COUNT(A1:A10) 4. IF function, used to make logical judgments based on specified conditions and return the corresponding result.

The advantages of default parameters in C++ functions include simplifying calls, enhancing readability, and avoiding errors. The disadvantages are limited flexibility and naming restrictions. Advantages of variadic parameters include unlimited flexibility and dynamic binding. Disadvantages include greater complexity, implicit type conversions, and difficulty in debugging.

The difference between custom PHP functions and predefined functions is: Scope: Custom functions are limited to the scope of their definition, while predefined functions are accessible throughout the script. How to define: Custom functions are defined using the function keyword, while predefined functions are defined by the PHP kernel. Parameter passing: Custom functions receive parameters, while predefined functions may not require parameters. Extensibility: Custom functions can be created as needed, while predefined functions are built-in and cannot be modified.

Exception handling in C++ can be enhanced through custom exception classes that provide specific error messages, contextual information, and perform custom actions based on the error type. Define an exception class inherited from std::exception to provide specific error information. Use the throw keyword to throw a custom exception. Use dynamic_cast in a try-catch block to convert the caught exception to a custom exception type. In the actual case, the open_file function throws a FileNotFoundException exception. Catching and handling the exception can provide a more specific error message.
