"Hello 클래스"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
잔글 (PSR 규칙에 맞게 서식수정)
 
5번째 줄: 5번째 줄:
[[category: PHP]]
[[category: PHP]]
<syntaxhighlight lang='php'>
<syntaxhighlight lang='php'>
class Hello {
class Hello
function __construct( $name ) {
{
$this->name = ucfirst($name);
}


function salute() {
    private $name;
echo "Hello $this->name!";
 
}
    function __construct($name)
    {
        $this->name = ucfirst($name);
    }
 
    function salute()
    {
        echo "Hello $this->name!";
    }
}
}



2022년 4월 2일 (토) 09:16 기준 최신판

Hello 클래스

1 PHP[ | ]

class Hello
{

    private $name;

    function __construct($name)
    {
        $this->name = ucfirst($name);
    }

    function salute()
    {
        echo "Hello $this->name!";
    }
}

$h = new Hello("john");
$h->salute();
# Hello John!

2 Ruby[ | ]

class Hello
   
   def initialize( name )
      @name = name.capitalize
   end

   def salute
      puts "Hello #{@name}!"
   end
   
end

h = Hello.new("john")
h.salute
# Hello John!

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}