Languages :: PHP :: Various questions |
|||
| By: yes4me |
Date: 28/07/2003 00:00:00 |
Points: 50 | Status: Answered Quality : Excellent |
|
True or false? If false, please let me know what is the ? Thanks. - There is no private variables in classes. They can only be declared public. - You can define a contructor but not a destructor in classes. - There is no thread functions in PHP. - If you have: class A1 { } class B2 extends A1 { } $objectVar1 = new A1(); $objectVar2 = new B2(); It is not possible to cast an object such as (A1)$objectVar3 = new B2; MySQL: Why would anyone need to add 10 in? Why not use INT instead of INT(10): CREATE TABLE tableName ( fieldName5 INT(10) ) PS: I am obviously running out of points... sorry about that. |
|||
| By: VGR | Date: 28/07/2003 17:17:00 | Type : Answer |
|
| - There is no private variables in classes. They can only be declared public. >> true - You can define a contructor but not a destructor in classes. >> true, PHP has a built-in scatter-gather mechanism deallocating all memory. It performs very well. - There is no thread functions in PHP. >> true and false. This clearly depends on the platform (OS), right ? Look on EE for questions like "multithreading" and "spawning a process" - If you have: [...] It is not possible to cast an object such as (A1)$objectVar3 = new B2; >> true, but this could work : $objectVar3 = (A1) new B2; MySQL: Why would anyone need to add 10 in? Why not use INT instead of INT(10): >> because this way, it's completely specified and cross-system enabled (portable). Just image systems where INTEGER would be in fact an INT(4) ?!? PS: I am obviously running out of points... sorry about that. >> you must be kidding :D a lot of people would help you for free :D |
|||
| By: VGR | Date: 28/07/2003 17:18:00 | Type : Comment |
|
| - There is no private variables in classes. They can only be declared public. >> true tru and false in fact. In fact, "var" members are ALL PUBLIC and may-be "non-var" ones ARE PRIVATE You can declare GLOBAL stuff so that it becomes public |
|||
| By: waygood | Date: 28/07/2003 18:03:00 | Type : Comment |
|
| I thought the point of classes was that you only interact with the data through the functions. So variable would only be local, within the class. But you can define them global if required. class bob { var globVar=10; // global function bob // constructor - same name as class { privVar=5; // private } } This way using the PHP function to list the methods and variables (get_class_vars, get_class_methods) only globVar and bob would get returned. |
|||
| By: waygood | Date: 28/07/2003 18:04:00 | Type : Comment |
|
| sorry! public not global |
|||
| By: wtgee | Date: 28/07/2003 18:54:00 | Type : Comment |
|
| waygood: In true OO design that is the point but I believe in PHP that is not the case (although I think I read something about that changing sometime). Nevertheless, you should pretend they are private and write accessor functions anyway. Well, if you want true OO design anyway. |
|||
| By: sumotimor | Date: 29/07/2003 01:55:00 | Type : Comment |
|
| Since it sounds like you're coming from a java background, I'd get started on PHP5, it will behave a lot more like you're expecting it to. There's a good overview of the new functions in PHP5 here: <A HREF="http://phpbuilder.com/columns/argerich20030411.php3">http://phpbuilder.com/columns/argerich20030411.php3</a> Support for private/public methods and variables, constructors, destructors, exceptions, and quite a few other goodies. |
|||
| By: VGR | Date: 29/07/2003 04:12:00 | Type : Comment |
|
| in a PHP3 page :D LOL |
|||
| By: yes4me | Date: 29/07/2003 10:42:00 | Type : Comment |
|
| FYI: class A1 { } class B2 extends A1 { } $objectVar1 = new A1(); $objectVar2 = new B2(); //Each of the following lines doesn't work $objectVar3 = (A3)new B3; $objectVar3 = (A3)new B3(); Now this code from php.net will work, but it is not exactly what I expected: function typecast($old_object, $new_classname) { if(class_exists($new_classname)) { $old_serialized_object = serialize($old_object); $new_serialized_object = 'O:' . strlen($new_classname) . ':"' . $new_classname . '":' . substr($old_serialized_object, $old_serialized_object[2] + 7); return unserialize($new_serialized_object); } else return false; } class A { var $secret; function A($secret) { $this->secret = $secret; } function output() { echo("Secret class A: " . $this->secret ." "); } } class B extends A { var $secret; function output() { echo("Secret class B: " . strrev($this->secret) ." "); } } $a = new A("Paranoia"); $b = typecast($a, "B"); $a->output(); $b->output(); echo("Classname \$a: " . get_class($a) . "Classname \$b: " . get_class($b)); |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








