php7 으로 업그레이드 후 발생하는 에러

php7 으로 업그레이드 후 발생하는 에러

QA

php7 으로 업그레이드 후 발생하는 에러

본문

[Fri May 19 19:52:34.957972 2017] [:error] [pid 17786] [client 172.30.1.254:56178] PHP Notice:  Only variables should be passed by reference in /home/html/plugin/torrent/bencode.php on line 145
[Fri May 19 19:52:34.958075 2017] [:error] [pid 17786] [client 172.30.1.254:56178] PHP Notice:  Only variables should be passed by reference in /home/html/plugin/torrent/bencode.php on line 160
[Fri May 19 19:52:34.958094 2017] [:error] [pid 17786] [client 172.30.1.254:56178] PHP Notice:  Only variable references should be returned by reference in /home/html/plugin/torrent/bencode.php on line 65

 

에러 내용입니다. 65줄 145줄 160줄에 에러가 있다고 나옵니다.

아래는 bencode.php 코드입니다. 

 

<?php
/*
TorrentEditor.com API - Simple API to modify torrents
Copyright (C) 2009  Tyler Alvord
 
Web: http://torrenteditor.com
IRC: #torrenteditor.com on efnet.org  
 
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
 
class BEncode
{
    public static function &decode( &$raw, &$offset=0 )
    {   
        if ( $offset >= strlen( $raw ) )
        {
            return new BEncode_Error( "Decoder exceeded max length." ) ;
        }
        
        $char = $raw[$offset];
        switch ( $char )
        {
            case 'i':
                $int = new BEncode_Int();
                $int->decode( $raw, $offset );
                return $int;
                
            case 'd':
                $dict = new BEncode_Dictionary();
 
                if ( $check = $dict->decode( $raw, $offset ) )
                {
                    return $check;
                }
                return $dict;
                
            case 'l':
                $list = new BEncode_List();
                $list->decode( $raw, $offset );
                return $list;
                
            case 'e':
                $ret = new BEncode_End(); 
                    return $ret; 
                
            case '0':
            case is_numeric( $char ):
                $str = new BEncode_String();
                $str->decode( $raw, $offset );
                return $str;
 
            default:
                return new BEncode_Error( "Decoder encountered unknown char '$char' at offset $offset." );
        }
    }
}
 
class BEncode_End
{
    public function get_type()
    {
        return 'end';
    }
}
 
class BEncode_Error
{
    private $error;
    
    public function BEncode_Error( $error )
    {
        $this->error = $error;
    }
    
    public function get_plain()
    {
        return $this->error;
    }
    
    public function get_type()
    {
        return 'error';
    }
}
 
class BEncode_Int
{
    private $value;
    
    public function BEncode_Int( $value = null )
    {
        $this->value = $value;
    }
 
    public function decode( &$raw, &$offset )
    {
            $end = strpos( $raw, 'e', $offset );
            $this->value = substr( $raw, ++$offset, $end - $offset );
            $offset += ( $end - $offset );
    }
 
    public function get_plain()
    {
        return $this->value;
    }
 
    public function get_type()
    {
        return 'int';
    }
    
    public function encode()
    {
        return "i{$this->value}e";
    }
    
    public function set( $value )
    {
        $this->value = $value;
    }
}
 
class BEncode_Dictionary
{
    public $value = array();
    
    public function decode( &$raw, &$offset )
    {
            $dictionary = array();
 
            while ( true )
            {
                $name = BEncode::decode( $raw, ++$offset );
 
                if ( $name->get_type() == 'end' )
                {
                    break;
                }
                else if ( $name->get_type() == 'error' )
                {
                    return $name;
                }
                else if ( $name->get_type() != 'string' )
                {
                    return new BEncode_Error( "Key name in dictionary was not a string." );
                }
 
                $value = BEncode::decode( $raw, ++$offset );
 
                if ( $value->get_type() == 'error' )
                {
                    return $value;
                }
 
                $dictionary[$name->get_plain()] = $value;
            }
 
            $this->value = $dictionary;
    }
    
    public function get_value( $key )
    {
        if ( isset( $this->value[$key] ) )
        {
            return $this->value[$key];
        }
        else
        {
            return null;
        }
    }
    
    public function encode()
    {
        $this->sort();
 
        $encoded = 'd';
        while ( list( $key, $value ) = each( $this->value ) )
        {
            $bstr = new BEncode_String();
            $bstr->set( $key );
            $encoded .= $bstr->encode();
            $encoded .= $value->encode();
        }
        $encoded .= 'e';
        return $encoded;
    }
 
    public function get_type()
    {
        return 'dictionary';
    }
    
    public function remove( $key )
    {
        unset( $this->value[$key] );
    }
    
    public function set( $key, $value )
    {
        $this->value[$key] = $value;
    }
    
    private function sort()
    {
        ksort( $this->value );
    }
    
    public function count()
    {
        return count( $this->value );
    }
}
 
class BEncode_List
{
    private $value = array();
    
    public function add( $bval )
    {
        array_push( $this->value, $bval );
    }
 
    public function decode( &$raw, &$offset )
    {
            $list = array();
 
            while ( true )
            {
                $value = BEncode::decode( $raw, ++$offset );
 
                if ( $value->get_type() == 'end' )
                {
                    break;
                }
                else if ( $value->get_type() == 'error' )
                {
                    return $value;
                }
                array_push( $list, $value );
            }
 
            $this->value = $list;
    }
    
    public function encode()
    {
        $encoded = 'l';
        
        for ( $i = 0; $i < count( $this->value ); ++$i )
        {
            $encoded .= $this->value[$i]->encode();
        }
        $encoded .= 'e';
        return $encoded;
    }
    
    public function get_plain()
    {
        return $this->value;
    }
 
    public function get_type()
    {
        return 'list';
    }
}
 
class BEncode_String
{
    private $value;
    
    public function BEncode_String( $value = null )
    {
        $this->value = $value;
    }
    
    public function decode( &$raw, &$offset )
    {
            $end = strpos( $raw, ':', $offset );
            $len = substr( $raw, $offset, $end - $offset );
            $offset += ($len + ($end - $offset));
            $end++;
            $this->value = substr( $raw, $end, $len );
    }
    
    public function get_plain()
    {
        return $this->value;
    }
    
    public function get_type()
    {
        return 'string';
    }
    
    public function encode()
    {
        $len = strlen( $this->value );
        return  "$len:{$this->value}";
    }
    
    public function set( $value )
    {
        $this->value = $value;
    }
}
 
?>

 

 

 

 

라인 65:                 return new BEncode_Error( "Decoder encountered unknown char '$char' at offset $offset." );

 

라인 145:                 $name = BEncode::decode( $raw, ++$offset );

 

라인 160:                $value = BEncode::decode( $raw, ++$offset );

 

이네요.

 

뭐가 잘못됐는지 모르겠어요. 도움 좀 부탁드립니다.

이 질문에 댓글 쓰기 :

답변 3

php7 으로 업그레이드 후 발생한 것이 아니라

기존에도 에러는 발생했겠지만 낮은 에러레벨 설정에 의해 나오지 않은것 뿐일것 같고,

환경이 바뀌면서 에러를 검출하는 레벨이 높아져서 그런것 같습니다.


그리고 에러메세지에서 나오듯이

전달 인자가 참조형 입니다.


foo->bar(1, 2);

foo->bar(1, $a++); 


$a = 1;

$b = 2;

foo->bar($a, $b); 


참조형이니 값을 전달하지 마시고


변수를 전달해야 한다고 답하신거네요


참조형은 메모리의 값을 기억하는 장소에 번지를 전달하는것이라서


값 자체를 전달하면 전달시 오류가 나오는거죠


답변을 작성하시기 전에 로그인 해주세요.
전체 69
QA 내용 검색
filter #php7 ×

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT