Use $this to refer to the current object. Use self to refer to the current class. In other words, use $this->member for non-static members, use self::$member for static members.
Source: When to use self vs this -stackoverflow
| # To use the "confirm" target inside another target, | |
| # use the " if $(MAKE) -s confirm ; " syntax. | |
| mycommand: | |
| @if $(MAKE) -s confirm ; then \ | |
| execute_your_command_here ; \ | |
| fi | |
| .PHONY: mycommand | |
| # The CI environment variable can be set to a non-empty string, |
| <VirtualHost *:80> | |
| ServerName hostname | |
| DocumentRoot /path/to/web | |
| DirectoryIndex app.php | |
| <Directory /path/to/web> | |
| Require all granted | |
| AllowOverride None | |
| </Directory> |
| // g++ -lstdc++ -Wno-write-strings fetch.cpp -o fetch | |
| #ifdef _WIN32 // Windows | |
| #include <winsock2.h> | |
| #include <ws2tcpip.h> | |
| #define MSG_NOSIGNAL 0 | |
| #else // Linux + Mac | |
| #include <sys/types.h> | |
| #include <sys/socket.h> | |
| #include <netinet/in.h> |
| function drips(){ | |
| docker ps -q | xargs -n 1 docker inspect --format '{{ .NetworkSettings.IPAddress }} {{ .Name }}' | sed 's/ \// /' | |
| } |
Use $this to refer to the current object. Use self to refer to the current class. In other words, use $this->member for non-static members, use self::$member for static members.
Source: When to use self vs this -stackoverflow
| <?php | |
| /** | |
| * This class can add WSSecurity authentication support to SOAP clients | |
| * implemented with the PHP 5 SOAP extension. | |
| * | |
| * It extends the PHP 5 SOAP client support to add the necessary XML tags to | |
| * the SOAP client requests in order to authenticate on behalf of a given | |
| * user with a given password. | |
| * |
| <?php | |
| $validator = new Validator(); | |
| // Each validation rule is a property of the validator object. | |
| $validator->username = function($value, $key, $self) | |
| { | |
| if(preg_match('~\W~', $value)) | |
| { | |
| return 'Your username must only contain letters and numbers'; |
| /***************************************************************************** | |
| * Copyright (c) 2011 Kenneth Waters | |
| * | |
| * | |
| * Permission is hereby granted, free of charge, to any person obtaining a | |
| * copy of this software and associated documentation files (the "Software"), | |
| * to deal in the Software without restriction, including without limitation | |
| * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
| * and/or sell copies of the Software, and to permit persons to whom the | |
| * Software is furnished to do so, subject to the following conditions: |