Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1094979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:03:08+00:00 2026-05-17T00:03:08+00:00

public function add($child){ return $this->children[]=$child; } Btw, this is an excerpt from PHP in

  • 0

public function add($child){
return $this->children[]=$child;
}

Btw, this is an excerpt from PHP in Action by Dagfinn Reiersol. According to the book, this returns $child, but shouldn’t it return true in case of successful assignment and false otherwise?

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:03:09+00:00Added an answer on May 17, 2026 at 12:03 am

    It returns $child. This is because $child is first added to the array $this->children[]. Then, the result of this assignment is returned.

    Essentially, it is shorthand for:

    public function add($child){
        $this->children[]=$child;
        return $child;
    }
    

    This type of shortcut works because, in PHP, assignment is “right-associative”: http://www.php.net/manual/en/language.operators.precedence.php

    This means that $a = ($b = 3) is actually evaluated from right-to-left, with 3 being stored in $b and then $a. Also, here is a note on the page I provided a link to:

    Although = has a lower precedence than
    most other operators, PHP will still
    allow expressions similar to the
    following: if (!$a = foo()), in which
    case the return value of foo() is put
    into $a.

    More information: http://en.wikipedia.org/wiki/Operator_associativity

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public function create($tableName, $userInput) { $this->db->insert($tableName, $userInput); return $this->db->affected_rows(); } As you see, $this->db->affected_rows();
When I add a public function to a standard code module in Excel it
Code in my moving object: ObjectX.Location.Add(Velocity * Utils.GetMoveDir(start, destination)); Utility function: public static PointF
Classes that implement IEnumerable and provide a public void Add(/* args */) function can
Public MaintenanceMenuList As ListView Function AddItems() Dim lstModules As New ListBox() MaintenanceMenuList.Items.Add(item_1) lstModules.Items.Add(MaintenanceMenuList) End
public function getItemsCollection($useCache = true) { if (is_null($this->_items)) { $this->_items = Mage::getModel('sales/quote_item')->getCollection(); $this->_items->setQuote($this); }
public function __construct($input = null) { if (empty($input)){ return false; } and then there's
My model is a simple parent/child representation looking like this public class Parent {
I have a function for fetching data from a database via a dataset public
public function action_adicionar_item() { $lista_item_pedido = array(); $x = 0; if(Session::has('lista_item_pedido')) { foreach(Session::get('lista_item_pedido') as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.