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.

[PHP5] Konstanten

Empfohlene Antworten

Veröffentlicht

Ich bin gerade am überlegen:

ich kann in einer php5 klasse ja konstanten als

const $constant;

definieren.

Ich könnte allerdings auch

private static $var

definieren und das ganze mit einem wert vorbelegen (final darf ich variablen glaub ich nicht definieren?).

Eigentlich ist die frage ja nicht wirklich sinnvoll ... aber nur um den unterschied oder auch nicht unterschied zwischen java und php in diesem zusammenhang zu erkennen ...

ich kann einer konstante kein Objekt zuweisen:

const $constant = new Object();

richtig?

mfg

Eth

P.S.: lasst euch zeit ich bin nun erstmal für ein paar Stunden nicht da ^^

einfach die begriffe richtig sortieren

Konstante:

const $constant;

Privat && Statisch

private static $var

es ginge sogar

private static const

denn es hat alles verschiedene bedeutungen

private = nur in der klasse sichtbar

static = statisch, egal wie viele viele Objekte du initiierst, es wird nur einmal

der statische anteil geladen

const = konstant, unveränderbare variable

>>definieren und das ganze mit einem wert vorbelegen (final darf ich variablen >>glaub ich nicht definieren?).

>>richtig, final nnur für objekte und methoden

>>const $constant = new Object();

>>richtig?

hat ich noch nie vor ;)

Hm, ok das mit den Konstanten war mir jetzt noch nicht so ganz klar wie PHP5 das handled.

In java ist das ja einfach als static final deklariert.

aber auch in java hat static nichts mit konstant zu tun ;)

public const string GRINSEKATZE = "Grinsie"

ergibt als Ergebnis in den meisten Programmiersprachen exakt das selbe wie

public static const string GRI ...

Da Konstanten im Regelfall 1 mal beim compilieren gesetzt wurden und danahc nicht mehr geändert werden.

public static string GRI ....

Diesmal ohne const ist keine Konstante, da es sich ändern lässt.

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.