Use Array_map error in class method---cannot redeclare

Source: Internet
Author: User
The method is defined as follows:
Class maaper{
......
Public Function getProperties () {
function GetName ($reflectionProperties) {
return $reflectionProperties->name;
}
$domain = $this->get_domain ();
$reflectionProperties = $domain->getproperties (reflectionproperty::is_public);
$properties =array_map (' GetName ', $reflectionProperties);
return $properties;
}

......
}


The invocation process is as follows (note: $mapper _1, $mapper _2 is called at the same runtime):

$mapper _1=new mapper ();
$mapper _2=new mapper ();

Var_dump ($mapper _1->getproperties ()); return correctly
Var_dump ($mapper _2->getproperties ()); Error cannot redeclare getName ()


As follows:





Reply to discussion (solution)

Don't you read the wrong message?
Fatal error:cannot redeclare getName ()
Fatal error: Cannot re-declare getName ()

class maaper{
protected function ge Tname ($reflectionProperties) {
return $reflectionProperties->name;
}
Public Function getProperties () {
$domain = $this->get_domain ();
$reflectionProperties = $domain->getproperties (reflectionproperty::is_public);
$properties =array_map (Array ($this, ' getName '), $reflectionProperties);
return $properties;
}

can also be written
class maaper{
Public Function getProperties () {
$getName = function ($reflectionPropert ies) {
return $reflectionProperties->name;
};
$domain = $this->get_domain ();
$reflectionProperties = $domain->getproperties (reflectionproperty::is_public);
$properties =array_map ($getName, $reflectionProperties);
return $properties;
}

Don't you read the wrong message?
Fatal error:cannot redeclare getName ()
Fatal error: Cannot re-declare getName ()

class maaper{
protected function ge Tname ($reflectionProperties) {
return $reflectionProperties->name;
}
Public Function getProperties () {
$domain = $this->get_domain ();
$reflectionProperties = $domain->getproperties (reflectionproperty::is_public);
$properties =array_map (Array ($this, ' getName '), $reflectionProperties);
return $properties;
}

can also be written
class maaper{
Public Function getProperties () {
$getName = function ($reflectionPropert ies) {
return $reflectionProperties->name;
};
$domain = $this->get_domain ();
$reflectionProperties = $domain->getproperties (reflectionproperty::is_public);
$properties =array_map ($getName, $reflectionProperties);
return $properties;
}
Thank you very much

But why is there a re-declared error?

You have
$reflectionProperties = GetProperties (reflectionproperty::is_public), $domain;
is to re-enter the getProperties, then the function defined in GetProperties is not repeated in the definition?

You have
$reflectionProperties = GetProperties (reflectionproperty::is_public), $domain;
is to re-enter the getProperties, then the function defined in GetProperties is not repeated in the definition?


Although there are two calls $domain-getProperties but the getProperties here is defined in the class to which the $domain domain object belongs, there is no GetName method. The error message is not able to re-affirm the GetName method located in GetProperties in class mapper.


So.... That's not what it looks like.

function GetName ($reflectionProperties) {
return $reflectionProperties->name;
}
Define global functions wherever you are

function GetName ($reflectionProperties) {
return $reflectionProperties->name;
}
Define global functions wherever you are
In a language.
Thank you!!!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.