Author Topic: stupid question about the code  (Read 147 times)

Offline noname8

  • Posts: 141
stupid question about the code
« on: December 11, 2018, 09:25:31 AM »
I inspected the most new code of website baker, 2.12.1
and found weird \ charachters that i've never seen before.
What they do and are called ?

frontend.functions. php:
Code: [Select]
if(isset($globals) AND \is_array($globals)) {

Code: [Select]
// Make sure block is numeric
            if (($block = \intval($block)) == 0 ) { $block = 1;}

the \ char in the if

Offline jacobi22

  • Posts: 5278
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: stupid question about the code
« Reply #1 on: December 11, 2018, 09:38:17 AM »
it marked a real php-function  (and not a user-defined function)

on other places, it has to do with the namespace  like \bin\helpers - see -> http://php.net/manual/en/language.namespaces.global.php
« Last Edit: December 11, 2018, 09:46:44 AM by jacobi22 »
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline noname8

  • Posts: 141
Re: stupid question about the code
« Reply #2 on: December 28, 2018, 04:16:05 PM »
Thank you!

Is this a standard way of coding php these days?
to me, seems like extra work -> not smart thing to do. I mean if i've made a php, i must already know what are reserved words from the lesson 0 almost.

Offline jacobi22

  • Posts: 5278
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: stupid question about the code
« Reply #3 on: December 28, 2018, 11:52:48 PM »
if you work with php or other kind of technologies, you've to learn every day - that's the way in this day's  :wink:

follow my link from the last post
Quote
Without any namespace definition, all class and function definitions are placed into the global space - as it was in PHP before namespaces were supported. Prefixing a name with \ will specify that the name is required from the global space even in the context of the namespace.

if you write a code only for yourself, it doesn't matter, what you do, it works or not
but if you work also for others, you have to use some standards
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline DarkViper

  • Forum administrator
  • *****
  • Posts: 2977
  • Gender: Female
Re: stupid question about the code
« Reply #4 on: December 29, 2018, 05:07:09 AM »

Is this a standard way of coding php these days?
Name spaces are definitely nothing new. This technique exists in different programming languages ​​partly already over 20 years.
In PHP it was introduced in 2009 with the version of PHP 5.3.0.  8-)
Also in recent years PHP itself has changed very much and is changing more and more with each new version. The new versions require ever stricter programming. On the other hand, they also offer many new possibilities that can make the programming itself easier and clearer. Unfortunately, WebsiteBaker is still away from the state of the art in terms of coding and it is urgently necessary to modernize essential parts in order to meet future requirements.

Also it is urgently necessary for programmers, to continue learning. To learn again and again with every new version.
Ultimately, Google will not be able to create your code, it only give hints in which direction you have to think. But you always have to program by yourself and you should understand what you do.
Namespaces, however, are only a small part of the new techniques, requirements. To be prepared for all these changes, it makes perfect sense, always to be in the best possible accordance with the official standards of the PHP Framework Interop Group (PHP Standards Recommendations).

Some information about PSR you can find here: WebsiteBaker-Wiki Coding Standards
Find some basical informations about Namespaces here: https://en.wikipedia.org/wiki/Namespace
or detailed here: php.net/manual/namespaces
Der blaue Planet - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen

"You have to take the men as they are… but you can not leave them like that !" :-P
Das tägliche Stoßgebet: Oh Herr, wirf ihnen Hirn vom Himmel !

 

postern-length