Superian Posted August 9, 2008 Share Posted August 9, 2008 I have no idea how to use the arrow syntax, so could someone please write a simple example that outputs a string using the arrow syntax? The arrow syntax should work without using OOP, correct? Thanks! $files->filename Quote Link to comment https://forums.phpfreaks.com/topic/118938-arrow-syntax/ Share on other sites More sharing options...
CaptainChainsaw Posted August 9, 2008 Share Posted August 9, 2008 It looks like you're calling the "filename" method on an object named "$files"..... therefor you're already using OOP. Here's a sample class how what I think you're trying to do: <?php class files{ private $_filename=''; public function __construct($filename){ $this->_filename=$filename; } public function filename(){ return $this->_filename; } } ?> Here's how you would instantiate it: <? $files = new files($filename); $files->filename(); ?> Hope this helps. CC Quote Link to comment https://forums.phpfreaks.com/topic/118938-arrow-syntax/#findComment-612424 Share on other sites More sharing options...
Superian Posted August 9, 2008 Author Share Posted August 9, 2008 It looks like you're calling the "filename" method on an object named "$files"..... therefor you're already using OOP. Here's a sample class how what I think you're trying to do: <?php class files{ private $_filename=''; public function __construct($filename){ $this->_filename=$filename; } public function filename(){ return $this->_filename; } } ?> Here's how you would instantiate it: <? $files = new files($filename); $files->filename(); ?> Hope this helps. CC There is no class, so how is OOP being used? I was thinking that there is way to use the arrow with out having to define a class, but I don't know how. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/118938-arrow-syntax/#findComment-612431 Share on other sites More sharing options...
rawb Posted August 9, 2008 Share Posted August 9, 2008 I don't think the arrow is used for anything outside of OOP. Unless you're just referencing an object's variable and not a method above I think what you're trying to accomplish is done with just a plain vanilla function <?php function filename() { // your code here } filename(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/118938-arrow-syntax/#findComment-612437 Share on other sites More sharing options...
CaptainChainsaw Posted August 9, 2008 Share Posted August 9, 2008 I agree. CC Quote Link to comment https://forums.phpfreaks.com/topic/118938-arrow-syntax/#findComment-612439 Share on other sites More sharing options...
Superian Posted August 9, 2008 Author Share Posted August 9, 2008 I don't think the arrow is used for anything outside of OOP. Unless you're just referencing an object's variable and not a method above I think what you're trying to accomplish is done with just a plain vanilla function <?php function filename() { // your code here } filename(); ?> There isn't a method nor is there a class! Quote Link to comment https://forums.phpfreaks.com/topic/118938-arrow-syntax/#findComment-612452 Share on other sites More sharing options...
wildteen88 Posted August 9, 2008 Share Posted August 9, 2008 The -> is used to access methods/properties within an object. An object is created when a class is initialized or from a function which returns an object (such functions are glob or mysql_fetch_object) Quote Link to comment https://forums.phpfreaks.com/topic/118938-arrow-syntax/#findComment-612454 Share on other sites More sharing options...
Superian Posted August 9, 2008 Author Share Posted August 9, 2008 The -> is used to access methods/properties within an object. An object is created when a class is initialized or from a function which returns an object (such functions are glob or mysql_fetch_object) (such functions are glob or mysql_fetch_object) I understand the mysql_fetch_object, but what do you mean by glob with in a function? Quote Link to comment https://forums.phpfreaks.com/topic/118938-arrow-syntax/#findComment-612459 Share on other sites More sharing options...
wildteen88 Posted August 9, 2008 Share Posted August 9, 2008 Sorry by glob I meant dir. I always get glob and dir mixed up. Quote Link to comment https://forums.phpfreaks.com/topic/118938-arrow-syntax/#findComment-612468 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.