"thinkphp" treacherous phenomenon, $this->rowuser[' ext '] = ' cannot be assigned! But Array_merge can

Source: Internet
Author: User
"thinkphp" strange Phenomenon, $this->rowuser[' ext '] = "; cannot be assigned! But Array_merge can!
Met a very strange thing, in the thinkphp3.1.3 inside.


/**
* Class useraction by <[email protected]>
*/
Class Useraction extends Initaction
{

Public Function Index ()
{
$where = Array (
' Mid ' = = Array (' eq ', $this->getuid ())
);
$this->rowuser = M (' Member ')->where ($where)->find ();

Test 1
$this->rowuser[' ext '] = ' name 4 ';
Dump ($this->rowuser); There is no ext this key!

Test 2 has
$arr [' ext '] = ' name 4 ';
$this->rowuser = Array_merge ($arr, $this->rowuser);
Dump ($this->rowuser); There's ext in there.


$this->rowuser2 = Array (
' A ' = ' a ',
' B ' = ' B ',
);
$this->rowuser2[' ext '] = ' 3333 ';
Dump ($this->rowuser2); There's no ext here either.
Die
}
}


What's going on here, it's weird!


------Solution--------------------
This method must be in the class or in the inherited class, just as the method that accesses the class $this-> the method name.
------Solution--------------------
If you have a __set, __get method defined in your useraction or its parent class, it is normal for this to happen.
Because they might not be able to make the cards.
------Solution--------------------
I've had the same problem.
TP is assigned in the controller, in fact, the __set method is assigned to the Tvar variable of the view class.
Then I discovered that the __set magic method has a bug that does not intercept an operation that assigns a value to an element of an array property directly:
$this->arr[' a '] = 1; So in TP is directly to $this->arr assignment, and we read is actually from $this->view->tvar
  • 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.