'WEB/PHP'에 해당되는 글 4건

47
18

What does static mean?

I know public means that it can be accessed from outside the class, and private only from inside the class…

 

 

42
 

Static means that it can be accessed without instantiating a class. This is good for constants.

Static methods need to have no effect on the state of the object. They can have local variables in addition to the parameters.'

 

 

 

 

40

public: Public declared items can be accessed everywhere.

protected: Protected limits access to inherited and parent classes (and to the class that defines the item).

private: Private limits visibility only to the class that defines the item.

static: A static variable exists only in a local function scope, but it does not lose its value when program execution leaves this scope.

final: Final keywords prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.


Beside of PHP:

transient: A transient variable is a variable that may not be serialized.

volatile: A variable that might be concurrently modified by multiple threads should be declared volatile. Variables declared to be volatile won't be optimized by the compiler because their value can change at anytime.

 

 

 

0

Example:

public class Methods_Test1 
{   
    public static void Display(String Name)
    {
        System.out.println("Hello There " + Name);
        System.out.println("I am from Display method");
    }


    public static void main(String[] args) 
    {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter name");
        String name = sc.next();
        Obj.Display(name);

    }

The public static void Display(String name) method accessible as static method within its own class which can be accessed without creating object of the class where as the same method behaves as public for the outside classes which can be accessed by creating object.

 

 

 

'WEB > PHP' 카테고리의 다른 글

The difference between "public" and "public static"?  (0) 2021.11.23
PHP 실행 지연(delay) 시키기  (0) 2021.11.23
mb_substr  (0) 2021.09.13
PHP Superglobal - $_REQUEST  (0) 2021.08.18
블로그 이미지

remoted

Remoted's IT LAB & POST DATABASE

댓글을 달아 주세요

PHP 스크립트(script) 실행(execution)시 테스트 등의 목적으로 실행을 지연(delay)시켜야할 경우가 있습니다. 이때 사용할 수 있는 함수 입니다.

 

 

1. 초 단위로 지연

 

int sleep ( int $seconds )

 

$seconds로 주어진 초 만큼 실행을 지연합니다. 성공시 0을 반환, 실패시 FALSE를 반환합니다. 음수를 지정하면 오류입니다. Warning이 발생합니다.

 

<?php
// ...
// 2초간 지연합니다.
sleep(2);
//...
?>

 

 

2. 마이크로초 단위로 지연

 

void usleep ( int $micro_seconds )

 

$micro_seconds로 주어인 마이크로 초(백만분의 1초) 만큼 실행을 지연합니다. 값을 반환하지 않습니다. 음수를 지정하면 오류입니다. Warning이 발생합니다.

 

<?php
// ...
// 2초간 지연합니다.
usleep(2000000);
// ...
?>

 

 

3. 지정된 시간까지 지연

 

bool time_sleep_until ( float $timestamp )

 

$timestamp 로 주어진 시간까지 지연합니다. 성공시 TRUE, 실패시 FALSE를 반환합니다. 과거 시간을 지정하면 오류입니다. Warning이 발생합니다.

 

<?php // 2초 지연 time_sleep_until(time() + 2); // 0.2초 지연 time_sleep_until(microtime(true) + 0.2); ?>

 

※ 참고

- int time(void) : January 1 1970 00:00:00 GMT 부터 지금까지의 초를 반환합니다.

- mixed microtime ([ bool $get_as_float = false ] ) : 현재의 타임스탬프를 마이크로초로 반환합니다. 인자로 주어지는 $get_as_float가 TRUE이면 마이크로초에 가장 근접한 초값을 float 타입으로 반환하고, FALSE 이면 string 타입의 값을 반환합니다.

 

PHP 프로그램을 지연시키는 다양한 방법을 알아보았습니다.



출처: https://offbyone.tistory.com/197 [쉬고 싶은 개발자]

'WEB > PHP' 카테고리의 다른 글

The difference between "public" and "public static"?  (0) 2021.11.23
PHP 실행 지연(delay) 시키기  (0) 2021.11.23
mb_substr  (0) 2021.09.13
PHP Superglobal - $_REQUEST  (0) 2021.08.18
블로그 이미지

remoted

Remoted's IT LAB & POST DATABASE

댓글을 달아 주세요

mb_substr

WEB/PHP 2021. 9. 13. 21:26

(PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8)

mb_substr  Get part of string

Description 

mb_substr(
    string $string,
    int $start,
    ?int $length = null,
    ?string $encoding = null
): string

Performs a multi-byte safe substr() operation based on number of characters. Position is counted from the beginning of string. First character's position is 0. Second character position is 1, and so on.

Parameters 

string

The string to extract the substring from.

start

If start is non-negative, the returned string will start at the start'th position in string, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth.

If start is negative, the returned string will start at the start'th character from the end of string.

length

Maximum number of characters to use from string. If omitted or NULL is passed, extract all characters to the end of the string.

encoding

The encoding parameter is the character encoding. If it is omitted or null, the internal character encoding value will be used.

Return Values 

mb_substr() returns the portion of string specified by the start and length parameters.

Changelog 

VersionDescription

8.0.0 encoding is nullable now.

See Also 

https://www.php.net/manual/en/function.mb-substr

 

'WEB > PHP' 카테고리의 다른 글

The difference between "public" and "public static"?  (0) 2021.11.23
PHP 실행 지연(delay) 시키기  (0) 2021.11.23
mb_substr  (0) 2021.09.13
PHP Superglobal - $_REQUEST  (0) 2021.08.18
블로그 이미지

remoted

Remoted's IT LAB & POST DATABASE

댓글을 달아 주세요

Super global variables are built-in variables that are always available in all scopes.


PHP $_REQUEST

PHP $_REQUEST is a PHP super global variable which is used to collect data after submitting an HTML form.

The example below shows a form with an input field and a submit button. When a user submits the data by clicking on "Submit", the form data is sent to the file specified in the action attribute of the <form> tag. In this example, we point to this file itself for processing form data. If you wish to use another PHP file to process form data, replace that with the filename of your choice. Then, we can use the super global variable $_REQUEST to collect the value of the input field:

Example

<html>
<body>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  Name: <input type="text" name="fname">
  <input type="submit">
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  // collect value of input field
  $name = $_REQUEST['fname'];
  if (empty($name)) {
    echo "Name is empty";
  } else {
    echo $name;
  }
}
?>


</body>
</html>

'WEB > PHP' 카테고리의 다른 글

The difference between "public" and "public static"?  (0) 2021.11.23
PHP 실행 지연(delay) 시키기  (0) 2021.11.23
mb_substr  (0) 2021.09.13
PHP Superglobal - $_REQUEST  (0) 2021.08.18
블로그 이미지

remoted

Remoted's IT LAB & POST DATABASE

댓글을 달아 주세요