[ Príspevkov: 7 ] 
AutorSpráva
Offline

Užívateľ
Užívateľ
Fatal error: Using $this when not in object context

Registrovaný: 02.09.08
Prihlásený: 11.01.14
Príspevky: 53
Témy: 24 | 24

Zdravím,
mám triedu a keď v nej volám $this (okrem konštruktora), tak mi vyhodí
Fatal error: Using $this when not in object context, hoci som vo vnútri objectu.

Takto nejak vyzerá ten kód:
Kód:
<?php

class Trieda {

private atribut

function __construct($atribut) {
    $this->atrubut = $atribut;
}

public function getAtribut() {
    return $this->atribut; // <-- tu dostavam ten Fatal Error.
}

}


Vopred ďakujem za odpovede.


Offline

Správca fóra
Správca fóra
Fatal error: Using $this when not in object context

Registrovaný: 27.07.07
Príspevky: 3948
Témy: 51 | 51
Bydlisko: Bratislava

Kód:
private $atribut;

Kód:
$this->atribut = $atribut;


_________________
NTB: Acer Aspire 4820TG 14" | CPU: Intel Core i5 2,53 GHz | VGA: ATI Mobility Radeon HD5650 1GB | RAM: 8GB DDR3 1066 MHz | HDD: 1TB SSD WD BLUE
Offline

Užívateľ
Užívateľ
Fatal error: Using $this when not in object context

Registrovaný: 02.09.08
Prihlásený: 11.01.14
Príspevky: 53
Témy: 24 | 24
Napísal autor témyOffline : 26.04.2010 15:33 | Fatal error: Using $this when not in object context

No jasne...to hej :) ja som toto písal len ako príklad na rýchlo :)
Takto to má byť:

Kód:
<?php

class Trieda {

private $atribut;

function __construct($atribut) {
    $this->atribut = $atribut;
}

public function getAtribut() {
    return $this->atribut; // <-- tu dostavam ten Fatal Error.
}

}


Offline

Správca fóra
Správca fóra
Fatal error: Using $this when not in object context

Registrovaný: 27.07.07
Príspevky: 3948
Témy: 51 | 51
Bydlisko: Bratislava

kod triedy je spravny... ako volas metodu getAtribut()?


_________________
NTB: Acer Aspire 4820TG 14" | CPU: Intel Core i5 2,53 GHz | VGA: ATI Mobility Radeon HD5650 1GB | RAM: 8GB DDR3 1066 MHz | HDD: 1TB SSD WD BLUE
Offline

Užívateľ
Užívateľ
Fatal error: Using $this when not in object context

Registrovaný: 02.09.08
Prihlásený: 11.01.14
Príspevky: 53
Témy: 24 | 24
Napísal autor témyOffline : 26.04.2010 15:45 | Fatal error: Using $this when not in object context

Kód:
Trieda::getAtribut()


Offline

Skúsený užívateľ
Skúsený užívateľ
Fatal error: Using $this when not in object context

Registrovaný: 30.05.06
Prihlásený: 08.10.14
Príspevky: 1756
Témy: 35 | 35
Bydlisko: BA - WESTSIDE

PHP manuál píše:
The Scope Resolution Operator :: (also called Paamayim Nekudotayim) or in simpler terms, the double colon, is a token that allows access to static, constant, and overridden properties or methods of a class.
Týmto operátorom sa volajú statické alebo prekryté metódy, alebo konštanty. Tá tvoja metóda nie je statická (tj. nie je spoločná pre všetky inštancie triedy, lebo pracuje s konkrétnymi hodnotami inštancii), takže ju musíš volať operátorom ->.


_________________
A. S. Tanenbaum píše:
The terms LF, MF, and HF refer to low, medium, and high frequency, respectively. Clearly, when the names were assigned, nobody expected to go above 10 MHz, so the higher bands were later named the Very, Ultra, Super, Extremely, and Tremendously High Frequency bands. Beyond that there are no names, but Incredibly, Astonishingly, and Prodigiously high frequency (IHF, AHF, and PHF) would sound nice.
Offline

Užívateľ
Užívateľ
Fatal error: Using $this when not in object context

Registrovaný: 02.09.08
Prihlásený: 11.01.14
Príspevky: 53
Témy: 24 | 24
Napísal autor témyOffline : 26.04.2010 16:40 | Fatal error: Using $this when not in object context

p360t

Dikes moc!!! ...SOLVED


 [ Príspevkov: 7 ] 


Fatal error: Using $this when not in object context



Podobné témy

 Témy  Odpovede  Zobrazenia  Posledný príspevok 
V tomto fóre nie sú ďalšie neprečítané témy.

This copy is not Geniue

v Windows

13

674

20.04.2009 20:19

Draex

V tomto fóre nie sú ďalšie neprečítané témy.

The requested URL /index.php was not found on this server.

v Windows

1

524

16.04.2014 16:04

simtoon

V tomto fóre nie sú ďalšie neprečítané témy.

Fatal error :(

v Hry a herné konzoly

14

1170

03.01.2010 21:27

Lettynko

V tomto fóre nie sú ďalšie neprečítané témy.

Cachtable fatal error

v Backend

2

496

01.01.2011 23:22

wolker

V tomto fóre nie sú ďalšie neprečítané témy.

Fatal system error

v Notebooky a netbooky

1

661

30.10.2009 23:26

kosican

V tomto fóre nie sú ďalšie neprečítané témy.

var_export - Fatal error

v Backend

8

582

05.02.2011 14:07

ThePlaky

V tomto fóre nie sú ďalšie neprečítané témy.

GTA IV Fatal Error

v Hry a herné konzoly

1

411

07.07.2013 12:18

Daron

V tomto fóre nie sú ďalšie neprečítané témy.

phpBB3 - chyba FATAL ERROR

v CMS

2

693

05.07.2007 7:29

cen3no

V tomto fóre nie sú ďalšie neprečítané témy.

fatal error C1510, LNK1104

v Backend

13

1019

24.11.2011 20:59

M4tros

V tomto fóre nie sú ďalšie neprečítané témy.

STOP:c000021a (FATAL System ERROR)

v Ostatné

6

2222

28.02.2010 8:56

marcel953

V tomto fóre nie sú ďalšie neprečítané témy.

Fatal Error: Controller monitor failed

v Pevné disky a radiče

7

678

21.06.2011 20:34

michalesku

V tomto fóre nie sú ďalšie neprečítané témy.

Ako na "DO NOT REMOVE THIS LINE!" ?

v Backend

13

728

17.02.2010 17:37

d0.0b

V tomto fóre nie sú ďalšie neprečítané témy.

windows setup could not configure windows to run on this com

v Windows

0

384

19.04.2012 14:18

Johnoo

V tomto fóre nie sú ďalšie neprečítané témy.

Fatal error: Access to undeclared static property...

v Backend

1

476

07.10.2010 10:41

coldak

V tomto fóre nie sú ďalšie neprečítané témy.

PLS POMOC!!! Ako preinstalovat OS??? (fatal error)

v Windows

16

2104

23.02.2008 22:27

walther

V tomto fóre nie sú ďalšie neprečítané témy.

Fatal error: Call to undefined function mysql_connect()

v Backend

5

766

05.02.2011 16:45

gamelaster



© 2005 - 2026 PCforum, edited by JanoF