These cousin languages bear a strong resemblance as well as clearly distinctive traits:
| C++ | PHP | |
| Class | Class MyClass : public BaseClass {} | class Class MyClass extends BaseClass {} |
| Inheritance | Multiple | Simple |
| Constructor | MyClass() {} | function MyClass() {} |
| Destructor | ˜MyClass() {} | None |
| Parameter Passing | By value but widespread use of pointers make it equivalent to references (references are also supported). | Passing objects by value by default has been making PHP the odd language out. PHP 5 will bring it in line with other object languages. |
| -> operator | Pointer to class or struct member. | Access to class member (would be "dot" in many languages, but dot is already string concatenation operator). Pointers are absent in PHP. |
| f()->g() calls | Can be arbitrarily nested. | Will be supported by PHP 5. Until then use saved returned value (a two-steps process) $r=&f(); // step 1 $r->g(); // step 2 |
| Type system | Statically typed. | Dynamically typed. |
| Strings | Not a native type (ASCIIZ). | Natively supported. |
| Arrays | Static | Dynamic— - Associative |
| Garbage collector | None, ; manage memory the hard way. | All system resources are garbage garbage-collected. |
| Preprocessor | Very elaborate. | Absent—define() supported. |
| Language level | L3G with L4G-like libraries. | L4G, sometimes strongly reminiscent of L3G. |
ไม่มีความคิดเห็น:
แสดงความคิดเห็น