Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Nutzen von Methoden in einem Array aus Objecten

Empfohlene Antworten

Veröffentlicht

Hei :)

Ich hab ein Prob. Also ich will für eine Ordnerverwaltung einen Baum aufbauen. Dazu hab ich mir ein Klasse node erstellt und diese würde ich nun gerne in ein Array stecken. Jedenfalls Klappt das füllen ja ganz gut, aber wenn ich mittels for-Schleife das ding auslesen will krieg ich einen Fehler:

Fatal error: Call to a member function on a non-object in D:\wwwroot\edv2\favoritenverw\confav.php on line 24

Das kommt bei


for($i=0;$i<count($tree);$i++) {

	echo($tree[$i]->getID());

}

?>


wenn ich statt der variable $i einen festen wert einsetze.. also einen der auch sicher im array is, dann funtz alles bestens (selbst wenn es in der for-Schleife steht.


wie gibt es dat?


Danke schonmal im vorraus.


Die Quellen kommen unten!

die [i]phpdb.php[/i] is nicht "wichitg"! 


Peace,


LoCal


tree.php

[code]

<?php

//$CR="\n\r";

$CR="<br>";

//session_register("uid");

$uid=39;

$first=true;


include("../phpdb.php");

include("classes.php");


echo("isch mach dat alles ma neu... weil isch will dat mit klassen und so machen");


$rs = ibase_query($intranet, "SELECT * FROM favoriten_ordner WHERE UID=".$uid."ORDER BY ID");

$tree[]=array();

while($row = ibase_fetch_object($rs)){

	//$tree[count($tree)]=new node;

	array_push($tree, new node);

	$tree[count($tree)-1]->setID($row->ID);

	$tree[count($tree)-1]->setMID(null);

	//$tree[count($tree)-1]->setParent(null);

}


for($i=0;$i<count($tree);$i++) {

	echo($tree[$i]->getID());

}


?>

[/code]


classes.zip

[code] <?php class node { var $id=-1; var $mid=-1; var $parent=""; var $childs; var $name=""; var $isLink=false; function setId($id) { $this->id = $id; } function setMid($mid) { $this->mid = $mid; } function setParent(&$parent) { $this->partent = $parent; } function addChild(&$child) { array_push($this->array,$child); } function setName($name) { $this->name = $name; } function setIsLink($isLink) { $this->isLink = $isLink; } function getID() { return $this->id; } function getMID(){ return $this->mid; } function getParent() { return $this->parent; } function getChild() { return $this->childs; } function getAmountOfChilds() { return count($childs); } function getName() { return $this->name; } function isLink() { return $this->isLink; } } ?>

Hei nochma..

hab den Fehler gefunden.

array_push() fügt immer ein weiteres array-feld an.. auch wenn das erste NULL is..

Peace,

LoCal

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.