please explain all the type for local. What is elements?

from Larry Ulman php tutorial

<?php # Script 7.5 - WorkUnit.php
// This page defines a WorkUnit class which uses the Composite pattern.
// This page also defines Team and Employee classes, which extend WorkUnit.

/* The WorkUnit class.
 * The class contains two attributes: $tasks and $name.
 * The class contains five methods: __construct(), getName(), add(), remove(), assignTask(), and completeTask().
 */
abstract class WorkUnit {
    
    // For storing work to be done:
    protected $tasks = array();

    // For storing the employee or team name:
    protected $name = NULL;
    
    // Constructor assigns the name:
    function __construct($name) {
        $this->name = $name;
    }
    
    // Method that returns the name:
    function getName() {
        return $this->name;
    }
    
    // Abstract functions to be implemented:
    abstract function add(Employee $e);
    abstract function remove(Employee $e);
    abstract function assignTask($task);
    abstract function completeTask($task);
    
} // End of WorkUnit class.

/* The Team class extends WorkUnit.
 * The class has one new attribute: $_employees.
 * The class has one new method: getCount().
 */
class Team extends WorkUnit {
    
    // For storing team members:
    private $_employees = array();
    
    // Implement the abstract methods...
    function add(Employee $e) {
        $this->_employees[] = $e;
        echo "<p>{$e->getName()} has been added to team {$this->getName()}.</p>";
    }
    function remove(Employee $e) {
        $index = array_search($e, $this->_employees);
        unset($this->_employees[$index]);
        echo "<p>{$e->getName()} has been removed from team {$this->getName()}.</p>";
    }
    function assignTask($task) {
        $this->tasks[] = $task;
        echo "<p>A new task has been assigned to team {$this->getName()}. It should be easy to do with {$this->getCount()} team member(s).</p>";
    }
     function completeTask($task) {
         $index = array_search($task, $this->tasks);
         unset($this->tasks[$index]);
         echo "<p>The '$task' task has been completed by team {$this->getName()}.</p>";
     }
    
    // Method for returning the number of team members:
    function getCount() {
        return count($this->_employees);
    }
    
} // End of Team class.

/* The Employee class extends WorkUnit.
 * The class has no new attributes or methods.
 */
class Employee extends WorkUnit {
    
    // Empty functions:
    function add(Employee $e) {
        return false;
    }
    function remove(Employee $e) {
        return false;
    }
        
    // Implement the abstract methods...
    function assignTask($task) {
        $this->tasks[] = $task;
        echo "<p>A new task has been assigned to {$this->getName()}. It will be done by {$this->getName()} alone.</p>";
    }
    function completeTask($task) {
        $index = array_search($task, $this->tasks);
        unset($this->tasks[$index]);
        echo "<p>The '$task' task has been completed by employee {$this->getName()}.</p>";
    }

} // End of Employee class.

Open in new window



<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Composite</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
<h2>Using Composite</h2>
<?php # Script 7. 8.6 - composite.php
// This page uses the WorkUnit, Team, and Employee classes (Script 7. 8.5).

// Load the class definition:
require('WorkUnit.php');

// Create the objects:
$alpha = new Team('Alpha');
$john = new Employee('John');
$cynthia = new Employee('Cynthia');
$rashid = new Employee('Rashid');

// Assign employees to the team:
$alpha->add($john);
$alpha->add($rashid);

// Assign tasks:
$alpha->assignTask('Do something great.');
$cynthia->assignTask('Do something grand.');

// Complete a task:
$alpha->completeTask('Do something great.');

// Remove a team member:
$alpha->remove($john);

// Delete the objects:
unset($alpha, $john, $cynthia, $rashid);
?>
</body>
</html>

Open in new window



please explain all the type for local
LVL 1
rgb192Asked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
If the code thing is an array such as _employees then the "elements" are not object properties...
I think the elements in this case are properties of the object.  They may be arrays instead of strings, but they are still properties.
0
 
Ray PaseurCommented:
"Local" and "Elements" may have specific meanings in computer science, but it's not apparent from the question what meanings they would have in this context.  These terms are not present in the code snippets.  Can you please give us a better explanation of what you're looking for?  Thanks.
0
 
Ray PaseurCommented:
Ahh, now I see it.  The word "elements" appears in the picture.

It appears to refer to the properties of the object.  For example, the $e object is an instance of the Employee class, which inherits from WorkUnit.  The two "elements" it contains are an array named tasks (defined in WorkUnit) and a string named name containing the value "Rashid" assigned in line 20 of the second code snippet.
0
 
Slick812Connect With a Mentor Commented:
greetings rgb192, I see you are still trying to learn about using objects in PHP.
Your question here is not about PHP, but about the "features" of the php programming text editor and code helper, maybe "nusphere phped".
In your what-are-elements.JPG  Image,  , , the "Code view" files are on the left view, you have the "workunit.php" in it in the image. You have the line selector in the "Team add" method of that php code file, , SO  your programming IDE automatically gives you a "View" in the right view of the code "structures-things" that are "executed" in the working code starting with -
$alpha = new Team('Alpha');

The "feature" in the right-view is suppose to tell you about some (not all) of the "code execution" for the Line selected  on the left, to HELP the developer (you) see some of what this add method is doing in code execution. No one can explain all of the right-view , because it will change every time the code section changes on the line selected in the left-view. Try and think of the right-view as an expanded php "var_dump" with info about this add method, and some of the assigned properties in the working code, , .

SO In this jpg image "line select" for right-view, it shows you that the $e in the method parameters add(Employee $e) is an object of Class Employee with two elements. In this IDE coding tags-references the "element" are things contained within that structure, in this case the object $e contains-holds 2 properties referred to as "elements" for "tasks" and "name" listed below.

If the code thing is an array such as _employees then the "elements" are not object properties but array elements that the array contains-holds, the 0 _employees-array element is an Object of Class Employee with two container elements.

if you were in left-view line selector for a "HTML thing" the the IDE elements would refer to any <div>, <b>, <span> that the "HTML thing" would contain-hold.

This is my help (guess) for this question, but it depends on the programming IDE not the language like PHP or javascript, or HTML
0
 
rgb192Author Commented:
thanks

I think the elements in this case are properties of the object.  They may be arrays instead of strings, but they are still properties.

Try and think of the right-view as an expanded php "var_dump" with info about this add method, and some of the assigned properties in the working code, , .
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.