PHP php new
Pokud vytvářite novou instanci nějakého objektu, musíte použít klíčové slovo new
class myClass {
private $var = 'Who I am? ';
function __construct($val){
$this->var .= $val;
}
function fc()
{
print 'Hello from myClass <br>';
print $this->var;
}
}
$myInstance = new myClass('I am a variable');
$myInstance->fc(); // Hello from myClass <br>Who I am? I am a variable
77LW NO topic_id
AD
Další témata ....(Topics)
// IF variable is not defined (or has a falsey value) THEN set it to an empty object.
// ELSE do nothing (technically speaking, variable gets assigned to itself)
var variable = variable || {} ;
function test(){
console.log(1);
}
// when called
test(); // 1
// or
var a = test;
a(); // 1
// or autocall if code executed
var test2 = function(){
console.log(2);
}
// test2 is undefined because the function test2 has no return value
// return string
function stringTest(param) {
return 'Hello ' + ' ' + param;
}
console.log(stringTest("Alice")); // Hello Alice
// return number
function numberTest(param) {
return 6 + param;
}
console.log(numberTest(5)); // 11
// or autocall if code executed
// function is like other variables
// parenthesis is for made groups or call functions.
// Immediately-Invoked Function Expression,
// or IIFE for short. It executes immediately after it’s created.
(function(){
// all your code here
var foo = function() {};
window.onload = foo;
// ...
})();
// foo is unreachable here (it’s undefined)
//////////////////////////////
// IIFE Immediately Invoked Funtion Expression
var greeting = function(name) {
return 'Hello ' + ' ' + name;
}('John');
console.log(greeting); // Hello John
console.log(typeof greeting); // string
console.log(greeting('Suzan')); // Uncaught TypeError: greeting is not a function
///////////////////////
var val = (function(){
var a = 0; // in the scope of this function
return function(x){
a += x;
return a;
};
})();
alert(val(10)); //10
alert(val(11)); //21
///////////////////////
// create the structure
var testHash = {
a : 1,
b : function(){
console.log(4);
},
c: function(param){
var num = param +5;
return num;
}
}
console.log(testHash.a); // 1
testHash.b(); // 4
testHash['b'](); // 4
testHash.c(7); // 12
/////////////////////////
// or function like class
function TestClass(n) {
this.some_property = n;
this.some_method = function() {
console.log(this.some_property);
};
}
var foo = new TestClass(3);
var bar = new TestClass(4);
foo.some_method(); // 3
bar.some_property += 2;
bar.some_method(); // 6
// console.log(some_property); // Uncaught ReferenceError: some_property is not defined
//////////////////////////
function Car(brand, year) {
return {
brand: brand,
year: year
}
}
var honda = Car("Honda", 1999);
console.log(honda.brand); // Honda
console.log(honda.year); // 1999
honda.brand = "Honda new Generation";
honda.year = 2021;
console.log(honda.brand); // Honda new Generation
console.log(honda.year); // 2021
var mazda = Car("Mazda",1987);
console.log(honda.brand); // Honda new Generation
console.log(mazda.brand); // Mazda
//////////////////////////////////////
// simplified code
var TEST_CLASS = TEST_CLASS || {};
TEST_CLASS.pokus = TEST_CLASS.pokus || (function() {
// -------------------------------------------------------------------------
// Private static variables and methods
// -------------------------------------------------------------------------
var privateStaticNumber = 5;
var privateStaticString = "My privateStaticString: ";
var privateStaticArray = [];
function privateStaticMethod(){
console.log('privateStaticMethod');
}
// CONSTRUCTOR CTOR
return function(config) {
// ----- private variables -----
var me = this,
isPaused = false;
this.privateStaticNumber = config.firstParam;
this.privateStaticString = privateStaticString + config.secondParam; // += produce: undefined I am from secondParam
this.privateStaticArray = config.thirtParam;
// ----- private methods -----
function getMode (mode, speed) {
// document.getElementById(mode).addEventListener('click', function () { snakeSpeed = speed; });
}
// ----- public variables -----
me.correct = 0;
me.wrong = 0;
// ----- public methods -----
me.setString = function(val) {
this.privateStaticString = val;
};
me.getString = function() {
return this.privateStaticString;
};
me.publicMethod = function(param){
console.log(param + ' from me.publicMethod()');
};
}; // end CTOR
})();
// end TEST_CLASS.pokus
var _me = _me || {};
var _me_test = new TEST_CLASS.pokus({firstParam:8, secondParam:" I am from secondParam", thirtParam:[1,3,9]});
// TEST_CLASS.pokus.privateStaticMethod(); // is not a function
// TEST_CLASS.pokus.publicMethod("Hola!"); // TEST_CLASS.pokus.publicMethod is not a function
// TEST_CLASS.publicMethod("Hola hej!"); // TEST_CLASS.publicMethod is not a function
// TEST_CLASS.pokus.publicMethod(" Hello!"); // is not a function
_me_test.publicMethod(" Hello!"); // Hello! from me.publicMethod()
console.log( _me_test.getString()); // My privateStaticString: I am from secondParam
console.log( _me_test.isPaused); // undefined
Date: 04.11.2020 - 23:14PHP function get first and latest character from string
// for earlier version PHP can use mb_strlen, mb_substr if use
// diacritical accent $str = 'ěščřžýáíé';
function startsWith($haystack, $needle)
{
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
}
function endsWith($haystack, $needle)
{
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}
Date: 11.06.2020 - 20:10htaccess rady a zkušenosti
Testování kódu htaccess ZDEPříklady na jakpsatweb
Dokumentace na apache.org
Testování regexů
Komentar nesmi byt na stejnem radku, jako kod. Zde jsou komentare, na konci radku (vedle) prikazu, jen kvuli snadnejsimu pochopeni kodu.
RewriteCond string (regex1) # tento radek nebude fungovat, koment musi byt na samostatnem radku, nejlepe nad provadenym kodem.
# tak je to spravne, komentar na samostatnem radku a nejlepe nad ukolem
RewriteCond string (regex1)
RewriteRule dosáhne jen na regex předchozího RewriteCond!
RewriteCond string (regex1) # nedosahne
RewriteCond string (regex2)
RewriteRule (regex) %1 # v %1 bude regex2
Číslo za % udává, kolikátá skupina předchozího regexu v RewriteCond bude použita. %0 vezme vše ze všech skupin.
Pokud skupina neexistuje, tak se vypíše jako %N , kde N je číslo skupiny, která nebyla nalezena.
$1 číslo za $ udává kolikátá skupina regexu bude použita, ale platí jen pro RewriteRule z jeho vlastního regexu. $0 vezme všchny skupiny (group) regexu z RewriteRule.
RewriteCond může být několikrát za sebou, ale jakmile se jedna z těchto podmínek nesplní, tak se nesplní ani následující RewriteRule!
RewriteCond # podmínka nesplněna
RewriteCond # splněna
RewriteRule # se nevykoná, protože jedna z podmínek nebyla splněna
RewriteRule přísluší vždy k předchozímu - předchozí skupině RewriteCond. Následující RewriteRule už je samostatné viz příklad:
RewriteCond
RewriteRule # tohle reaguje na předchozí podmínku a vykoná se, když je podmínka splněna
RewriteRule # tohle už je samostatné a nebude brát ohled na podmínku - podmínky v předchozích řádcích.
Využití regexu, který bude vytvořen až v následujícím RewriteRule. Regex Back-Reference Availability
Date: 27.02.2020 - 11:11
Letní čas tak připočítat hodinu.
Ověření zda je letní čas.
$dst = date("I"); //I (capital i); 0 or 1 if daylight saving time
// example:
$hour = 14;
if(date("I")===1){
$hour = $hour + 1;
}
// OR
$hour = 14 + date("I");
Pro psaní příspěvků můžeme vkládat další vlastní tlačítka, která vkládají tagy v hranatých závorkách
Podrobně o této tématice na odkaze níže.
//www.phpbb.com/kb/article/adding-custom-bbcodes-in-phpbb3/
**VIDEO YOUTUBE
Podrobně o této tématice na odkaze níže.
//www.phpbb.com/kb/article/adding-custom-bbcodes-in-phpbb3/
**VIDEO YOUTUBE
Editace: 18 10 2016
Počet článků v kategorii: 77
Url:php-new