Php, perl, question. what does it mean: "$ variable & # 8594; performs some function"

I saw this (example: $ variable → define something ) in both perl and php, but I have never used it before. What is the purpose of this statement → Does it assign a value or pass a parameter?

thank

+5
source share
3 answers

Php

It is used in OOP, it can be a method (but then at the end there will be be ()) or a class property. I don't know perl, so I can’t tell you what it is, but for php: Some examples that hopefully clarify:

We can make a class object in php as follows:

$object = new MyClass();

, , :

$object -> getInstance();

, , :

echo $object -> instance;

, getter :

class MyClass { 

   // property instance 
   private $instance; 

   protected __construct() 
   { 

   } 
   // getInstance method 
   protected static function getInstance() 
   { 
      return $this -> instance;
   }
}

http://php.net/manual/en/language.oop5.php

Perl

$obj->$a $a $obj. , : $obj->$a() URL: http://perldoc.perl.org/perlop.html#The-Arrow-Operator

-1

Perl -> , , , . rhs [...], {...}, (...) . $some_name some_name, .

my $array_ref = [1, 2, 3];

say $array_ref->[2];  # prints 3
say $$array_ref[2];   # also prints 3

my $hash_ref = {a => 1, b => 2};

say $hash_ref->{b};   # prints 2
say $$hash_ref{b};    # also prints 2

my $code_ref = sub {"[@_]"};

say $code_ref->('hello');  # prints "[hello]"
say &$code_ref('hello');   # also prints  "[hello]"

my $object = Some::Package->new();

$object->some_method(...);  # calls 'some_method' on $object

my $method = 'foo';

$object->$method(...);   # calls the 'foo' method on $object

$object->$code_ref(...);  # same as $code_ref->($object, ...)

-> .

+9

As for perl, an operator ->can mean:

Oh, and maybe I forgot something.

+3
source

All Articles