php.de

Zurück   php.de > Webentwicklung > PHP Einsteiger > PHP Tipps 2008

 
 
LinkBack Themen-Optionen Thema bewerten
Alt 18.08.2008, 02:25  
Neuer Benutzer
 
Registriert seit: 18.08.2008
Beiträge: 1
campinge befindet sich auf einem aufstrebenden Ast
Standard Call to a member function on a non-object

Hallo erstmal!

Sorry, wenn ich schon wieder einen derartigen thread aufmache, aber ich habe einfach nix ausreichend erklärendes dazu gefunden.

Ich beschäftige mich schon seit geraumer zeit mit php und mittlerweile klappt fast alles auch relativ gut.
Heute habe ich mich mal an Funktionen gewagt und bin prompt auf die Nase gefallen.

Ich habe eine Startseite, die, sofern keine Session gestartet ist, eine funktion aufrufen soll, die die session startet.
nun hatte ich mir das in einem beispielscript angeguckt und munter drauf losprogrammiert und durfte am ende feststellen, dass nix läuft.

Code:
Fatal error:  Call to a member function on a non-object in /www/[...]/index.php on line 7 
hier der aufruf:
PHP-Code:
4: include("include/session.php");
5: Global $session;
6: if (!isset($_SESSION['username'])) {
7:     $session->start_session();
8: } 
dann gehts hierhin:
(sessionskript mal testweise gekillt, bringt aber genau das selbe ergebnis..)
PHP-Code:
class session
{
    var 
$username;              /**contains username**/
    
var $userid;                /**contains user id**/
    
var $userlevel;             /**contains userlevel**/
    
var $time;                  /**contains login time**/
    
var $date;                  /**contains login date**/
    
var $logged_in;             /**contains true if logged in, else false**/
    
var $userinfo=array();      /**contains all userinfo from the database**/
    
var $url;                   /**contains the current site url**/
    
var $referrer;              /**contains last site url**/
    
    
    /**
     * Start_session is used when user enters the site
     * it checks if a session is running or if a cookie
     * has been saved the sat time. If one of them is true,
     * the usersession will be startet, otherwise a
     * guest session will be created
     **/
    
function start_session() {

    
$this->username"guest";
    echo 
$this->username;
}

Wo liegt da jetzt der hund begraben?
campinge ist offline  
Sponsor Mitteilung
PHP Code Flüsterer

Registriert seit: 21.08.2005
Beiträge: 4682
PHP-Kenntnisse:
Fortgeschritten

Alt 18.08.2008, 02:31  
moderatives Dielektrikum
 
Benutzerbild von nikosch
 
Registriert seit: 21.05.2008
Beiträge: 35.988
PHP-Kenntnisse:
Fortgeschritten
nikosch hat eine strahlende Zukunftnikosch hat eine strahlende Zukunftnikosch hat eine strahlende Zukunftnikosch hat eine strahlende Zukunftnikosch hat eine strahlende Zukunftnikosch hat eine strahlende Zukunftnikosch hat eine strahlende Zukunftnikosch hat eine strahlende Zukunftnikosch hat eine strahlende Zukunftnikosch hat eine strahlende Zukunftnikosch hat eine strahlende Zukunft
Standard

start_session ist eine sogenannte Methode. Eine Funktion innerhalb eines Klassenobjektes. Um die Methode aufzurufen muß ein entsprechendes Objekt instanziiert worden sein. Für den Aufruf $session->start_session(); müßte $session ein Objekt mit der gegebenen Methode enthalten. Dass dies nicht der Fall ist sagt
Zitat:
Call to a member function on a non-object
aus.
Weitere Hinweise findest Du im Manual unter OOP (Objektorientierte Programmierung) und new Operator.
__________________
--
One pixel is still too big. Please make it smaller. ASAP.

Initiative Mittelstand.
Die wichtigste Gestaltungsregel im Screendesign ist Pi mal Daumen des Arbeitgebers.
--
nikosch ist gerade online  
 


Themen-Optionen
Thema bewerten
Thema bewerten:

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an
Gehe zu

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
[Erledigt] Fatal Error:"Call to a member function on a non-object" Floyd PHP Tipps 2008 4 15.08.2008 13:35
Call to a member function ... on a non-object funnx PHP Tipps 2008 6 29.07.2008 18:08
Fatal error: Call to a member function on a non-object tweek PHP Tipps 2008 13 25.06.2008 12:56
Fatal error: Call to a member function on a non-object atom-dragon PHP Tipps 2007 20 02.12.2007 22:22
Call to a member function on a non-object Riks PHP Tipps 2007 20 10.02.2007 22:59
Fatal error: Call to undefined function mail() PHP Tipps 2005-2 16 04.07.2005 13:24
Problem Call to a member function on a non-object PHP Tipps 2005 5 24.05.2005 19:14
Call to a member function on a non-object PHP Tipps 2005 12 24.05.2005 04:06
Fatal error: Call to a member function on a non-object PHP Tipps 2005 7 13.04.2005 07:24
update auf php 5.0.4 robo47 Server, Hosting und Workstations 6 10.04.2005 19:00
Fatal error: Call to a member function on a non-object PHP Tipps 2005 15 04.02.2005 13:02
Fatal error: Call to undefined function: imagecreatefromjpeg DannyD PHP-Fortgeschrittene 10 05.12.2004 21:59
Call to a member function on a non-object --> WARUM ? PHP Tipps 2004-2 4 25.11.2004 20:16
[Erledigt] Call to undefined function highlight() PHP Tipps 2004 1 07.09.2004 09:31
[Erledigt] Fatal error: Call to undefined function:... PHP Tipps 2004 8 27.06.2004 12:56

Besucher kamen über folgende Suchanfragen bei Google auf diese Seite
all to a member function on a non-object, member function on a non-object, php fatal error: call to a member function on a non-object in, fatal error: call to a member function save() on a non-object in, call to a member function getsessioneduser() on a non-object, \fatal error: call to a member function current() on a non-object \, call to a member function save() on a non-object, \call to a member function current()\, call to a member function logged_in() on a non-object, call to a member function on a non-object, call php function, php member objekt, call to a member function of a non-object, php objekt indirekt instanziieren, on a non-object, call to a member function saveas() on a non-object, fatal error: call to a member function create() on a non-object, fatal error: call to a member function mark() on a non-object in /users/ on line 24, fatal error: call to a member function on a non-object in on line 24, fatal error: call to a member function logged_in() on a non-object

Alle Zeitangaben in WEZ +2. Es ist jetzt 16:52 Uhr.




Powered by vBulletin® Version 3.7.2 (Deutsch)
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Aprilia-Forum, Aquaristik-Forum, Liebeskummer-Forum, Zierfisch-Forum, Geizkragen-Forum