PHP, JScript and VBScript functions and class syntax _ PHP Tutorial

Source: Internet
Author: User
Tags define local
PHP, JScript, and VBScript functions and class syntax. 1) function example php: functioninc ($ val) {return $ val + 1;} is also a function, but no return value. Example of the jscript, javascript: functioninc (val) {returnval + 1;} process 1) function
Php: function inc ($ val)
{Return $ val + 1 ;}

The process is also a function, but there is no return value.
Jscript, javascript:
Function inc (val)
{Return val + 1 ;}
The process is defined 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 (){}
}

/* Inherit */
Class child extends parent {var property = new value;
}

Jscript or javascript:
Class parent {
Property = value
Function parent () function method (){}}

Inheritance is not supported (the original document is like this, but it seems that inheritance is supported now)
Vbscript:
Does not support classes (The original article is like this, but now also supports)

3) variable range
Php: variables allow global variables in functions or out-of-class definitions. you can also define local variables in functions and classes.
Unlike other languages, when using variables, you must name a global variable and use the keyword global in functions and classes.
$ Globalvar = 1;
Function show_global (){
Global $ globalvar;
Print $ globalvar;
}
Jscript or javascript:
Similar to PHP, global variables do not need to be declared in functions.
Vbscript:
Similar to PHP, global variables do not need to be declared in functions and procedures.

4) access reference
Php: use keywords in function parameters.
Jscript or javascript
Simple access through variables, referencing complex types in functions
Vbscript:
Use the ByRef keyword in the Sub or function parameters.

5) default parameters
Php: function A (param1 = "abc") is supported ")
Others are not supported.

6) return a reference (I do not know how to flip)
Php: function getarray123 (){
$ Val = array (1, 2, 3 );
Return & $ val;
}
Then use

$ Val = & getarray123 ();
Other unsupported

7) class
Php: better support
Others: Average

8) handle errors
Php: Use @ to prevent running errors.

$ Val = @ function_can_fail ();

@ The range is the current Declaration. The final 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:
Ignore running errors using On Error Resume Next
The new version also supports try and catch.

In addition, there is a comparison about language. if you are interested, you can translate it.


Http://www.bkjia.com/PHPjc/532501.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/532501.htmlTechArticle1) function example php: function inc ($ val) {return $ val + 1;} the process is also a function, but there is no return value. Jscript, javascript: function inc (val) {return val + 1;} process...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.