728x90
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' 카테고리의 다른 글

[고도몰 Pro+] SFTP 접속이 안됨과 동시에 문제 해결하기  (0) 2023.05.25
FTP 설정 방법 - 고도몰  (0) 2023.05.18
PHP 실행 지연(delay) 시키기  (0) 2021.11.23
mb_substr  (0) 2021.09.13
PHP Superglobal - $_REQUEST  (0) 2021.08.18
728x90

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 [쉬고 싶은 개발자]

728x90

Class 'ZipArchive' not found 에러가 발생하는 이유는 zip 모듈이 없어서이다.

phpinfo() 하여서 확인해보면 알 수 있다.

 

모듈을 설치하려면 PHP 다시 컴파일하거나 모듈만 설치하는 방법이 있다.

귀찮으니 모듈만 따로 설치하자.

Zip 모듈은 pecl 에서 다운로드 받으면 된다. 여기서 Stable 버전을 다운받는다.

http://pecl.php.net/package/zip

 

wget http://pecl.php.net/get/zip-1.10.2.tgz

압축을 해제하고

tar xvfz zip-1.10.2.tgz

cd zip-1.10.2

phpize     (혹시 phpize: command not found 라고 나오면 yum install php-devel  한후 다시 실행)

./configure --with-php-config=/usr/local/php/bin/php-config --enable-zip && make

cd modules/

ls 를 하면 zip.la  zip.so 가 보인다.

zip.so를 php 확장 디렉토리로 복사한다.

cp zip.so /usr/local/php/lib/php/extensions

php 설정파일을 열어서 zip.so 부분을 추가해준다.

vi /etc/php.ini

extension_dir="/usr/local/php/lib/php/extensions"

extension="zip.so" 를 추가.

/usr/local/apache2/bin/apachectl restart



출처: https://mara.tistory.com/327 [Absolute Purpose]

 

In CentOS 7.4 

yum install php-pecl-zip

 

+ Recent posts