ballhogjoni Posted September 9, 2008 Share Posted September 9, 2008 is it safe to say that an object is technically an array? Link to comment https://forums.phpfreaks.com/topic/123452-is-it-safe-to-say/ Share on other sites More sharing options...
JonnoTheDev Posted September 9, 2008 Share Posted September 9, 2008 Not really - where did you get that idea Link to comment https://forums.phpfreaks.com/topic/123452-is-it-safe-to-say/#findComment-637625 Share on other sites More sharing options...
discomatt Posted September 9, 2008 Share Posted September 9, 2008 Not at all. Objects are objects, arrays are arrays I know PHP can be redundant at times, but that would just be ridiculous Link to comment https://forums.phpfreaks.com/topic/123452-is-it-safe-to-say/#findComment-637627 Share on other sites More sharing options...
Mchl Posted September 9, 2008 Share Posted September 9, 2008 Objects in PHP4, where all properties were public, could indeed behave similarly to arrays. Even then, I wouldn't say they're the same. Link to comment https://forums.phpfreaks.com/topic/123452-is-it-safe-to-say/#findComment-637628 Share on other sites More sharing options...
ballhogjoni Posted September 9, 2008 Author Share Posted September 9, 2008 Can someone explain the difference then. I got the idea because if you print_r an object or an array it will give you the same structure: object([0]=>somecontent); array([0]=>somecontent); Link to comment https://forums.phpfreaks.com/topic/123452-is-it-safe-to-say/#findComment-637748 Share on other sites More sharing options...
BlueSkyIS Posted September 9, 2008 Share Posted September 9, 2008 that's one coincidental example you've got there. one example of a difference is that an object can have internal and external functions. Link to comment https://forums.phpfreaks.com/topic/123452-is-it-safe-to-say/#findComment-637757 Share on other sites More sharing options...
ballhogjoni Posted September 9, 2008 Author Share Posted September 9, 2008 Quote internal and external functions. Do you mean something like: object([0]=>somefunction()); Link to comment https://forums.phpfreaks.com/topic/123452-is-it-safe-to-say/#findComment-637759 Share on other sites More sharing options...
BlueSkyIS Posted September 9, 2008 Share Posted September 9, 2008 this does a much better job explaining things than i can: http://us.php.net/zend-engine-2.php simple example: class SomeObject { function doSomething () { echo "hello world!"; } } $thisObject = new SomeObject(); $thisObject->doSomething; output: hello world! Link to comment https://forums.phpfreaks.com/topic/123452-is-it-safe-to-say/#findComment-637762 Share on other sites More sharing options...
Mchl Posted September 9, 2008 Share Posted September 9, 2008 Actually $thisObject->doSomething(); I think methods have to be called with parentheses even if there are no required parameters... haven't they? Link to comment https://forums.phpfreaks.com/topic/123452-is-it-safe-to-say/#findComment-637846 Share on other sites More sharing options...
BlueSkyIS Posted September 9, 2008 Share Posted September 9, 2008 yes. my bad. class SomeObject { function doSomething () { echo "hello world!"; } } $thisObject = new SomeObject(); $thisObject->doSomething(); Link to comment https://forums.phpfreaks.com/topic/123452-is-it-safe-to-say/#findComment-637849 Share on other sites More sharing options...
Mchl Posted September 9, 2008 Share Posted September 9, 2008 I pretty often do it the other way i.e. I use $mysqli->error(); where it should be $mysqli->error; Link to comment https://forums.phpfreaks.com/topic/123452-is-it-safe-to-say/#findComment-637865 Share on other sites More sharing options...
JonnoTheDev Posted September 9, 2008 Share Posted September 9, 2008 class myClass { public $i; public function __construct() { $this->i = 5; } public function i() { // method code return 2; } } $x = new myClass(); // will set $y to 5 $y = $x->i; // will set $y to 2 $y = $x->i(); See the differences above. The first is a ref to a class variable. The second is a class method Link to comment https://forums.phpfreaks.com/topic/123452-is-it-safe-to-say/#findComment-637892 Share on other sites More sharing options...
lisa71283 Posted September 9, 2008 Share Posted September 9, 2008 Quote Actually $thisObject->doSomething(); I think methods have to be called with parentheses even if there are no required parameters... haven't they? Yes, they do. Link to comment https://forums.phpfreaks.com/topic/123452-is-it-safe-to-say/#findComment-637894 Share on other sites More sharing options...
BlueSkyIS Posted September 9, 2008 Share Posted September 9, 2008 Quote Quote Actually $thisObject->doSomething(); I think methods have to be called with parentheses even if there are no required parameters... haven't they? Yes, they do. Quote yes. my bad. class SomeObject { function doSomething () { echo "hello world!"; } } $thisObject = new SomeObject(); $thisObject->doSomething(); Link to comment https://forums.phpfreaks.com/topic/123452-is-it-safe-to-say/#findComment-637896 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.