网络营销电子商务研究中心  
How to buy the best prescription safety glasses in Canada? Let's study!
Go Back   网络营销电子商务研究中心 > 网站建设 > 代码交流
User Name
Password
 
FAQ Members List Calendar Cheap Glasses

代码交流 ASP,PHP,JSP等网站源代码下载与交流。

Reply
 
Thread Tools Display Modes
  #1   IP: 218.2.29.60
Old 2006-12-15, 07:36 PM
smiling smiling is offline
高级会员
 
Join Date: 2006-02-12
Posts: 502
smiling 正向着好的方向发展
Default PHP,JScript和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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump

Prescription-glasses.com offers prescription glasses online at discount prices.
All times are GMT +8. The time now is 11:08 AM.


Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.