Jump to content

Arrow Syntax


Superian

Recommended Posts

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 :)

Link to comment
https://forums.phpfreaks.com/topic/118938-arrow-syntax/#findComment-612424
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/118938-arrow-syntax/#findComment-612431
Share on other sites

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();

?>

 

Link to comment
https://forums.phpfreaks.com/topic/118938-arrow-syntax/#findComment-612437
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/118938-arrow-syntax/#findComment-612452
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/118938-arrow-syntax/#findComment-612459
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.