php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18014 Pointers idea in OOP if PHP not consitent
Submitted: 2002-06-27 06:06 UTC Modified: 2002-06-27 06:18 UTC
From: davidktw at singnet dot com dot sg Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 4.2.1 OS: Windows 2000 Pro
Private report: No CVE-ID: None
 [2002-06-27 06:06 UTC] davidktw at singnet dot com dot sg
class Node
{
	var $name;
	var $next;

	function Node($name)
	{
		$this->name = $name;
		$this->next = NULL;
	}

	function getNext()
	{
		return $this->next;
	}

	function setNext($next)
	{
		$this->next = $next;
	}
}

$head = new Node("david");
$curr = $head;
$curr->setNext(new Node("peter"));
$curr = $curr->getNext();
$curr->setNext(new Node("john"));

$curr = $head;
while ($curr)
{
	print("<p>".$curr->name."</p>");
	$curr = $curr->getNext();
}

The problem with the code above is.. only "david" is printed.. why isn't the rest of the Nodes printed ?
I have checked the linkage
If seems like $curr->next is NULL instead of the next Node in the linkedlist... What have I did wrongly ?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-27 06:18 UTC] sander@php.net
Sorry, but the bug system is not the appropriate forum for asking
support questions. Your problem does not imply a bug in PHP itself.
For a list of more appropriate places to ask for help using PHP,
please visit http://www.php.net/support.php

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 03:01:29 2024 UTC