从__constructor返回false(Return false from __constructor)
你能否从构造函数返回false?
<?php class ftp_stfp{ //private vars of the class private $host; private $username; private $password; private $connection_type; private $connection = false; function __contruct( $host, $username, $password, $connection_type ){ //setting the classes vars $this->host = $host; $this->username = $username; $this->password = $password; $this->connection_type = $connection_type; //now set the connection into this classes connection $this->connection = $this->connect(); //check the connection was set else return false if($this->connection === false){ return false; } } ... etc etc the rest of the class
致电课程:
$ftp_sftp = new ftp_sftp( $host, $uname, $pword, $connection_type );
这实际上是正确的,也就是说$ ftp_sftp var是false还是保持类取决于__construct方法的结果,还是这是完全错误的逻辑?
Can you return false from the contructor?
<?php class ftp_stfp{ //private vars of the class private $host; private $username; private $password; private $connection_type; private $connection = false; function __contruct( $host, $username, $password, $connection_type ){ //setting the classes vars $this->host = $host; $this->username = $username; $this->password = $password; $this->connection_type = $connection_type; //now set the connection into this classes connection $this->connection = $this->connect(); //check the connection was set else return false if($this->connection === false){ return false; } } ... etc etc the rest of the class
Call the class:
$ftp_sftp = new ftp_sftp( $host, $uname, $pword, $connection_type );
Is this actually correct, ie would the $ftp_sftp var either be false or hold the class depending on outcome of the __construct method, or is this completely wrong logic?
原文:https://stackoverflow.com/questions/14295761
最满意答案
当你在同一个文件系统上创建一个文件时,系统只需要改变目录条目以反映你的重命名。 文件中的数据甚至没有被读取。
(相同的文件系统意味着:相同的目录或相同的目录树/同一个驱动器,前提是源目录和目标目录不会遍历导致另一个文件系统的符号链接!)
当你跨越文件系统创建一个文件时,它与cp + rm具有相同的效果:没有速度增益(除了你只运行一个命令并保证一致性的事实:你不必检查cp是否成功执行rm)
(旧版本的mv拒绝在文件系统中移动目录,因为它们只做了重命名)
小心,它不等同。 默认情况下,
cp
覆盖目标,而mv
将无法将文件/目录重命名为现有文件/目录。When you mv a file on the same filesystem, the system just has to change directory entries to reflect your renaming. Data in the file is not even read.
(same filesystem means: same directory or same directory tree/same drive, provided that source and destination directories do not traverse symlinks leading to another filesystem of course!)
When you mv a file across file systems, it has the same effect as cp + rm: no speed gain (apart from the fact that you only run one command, and consistency is guaranteed: you don't have to check if cp succeeded to perform the rm)
(older versions of mv refused to move directories across filesystems, because they only did the renaming)
Be careful, it is not equivalent.
cp
overwrites destination by default, whereasmv
will fail renaming a file/dir into an existing file/dir.
相关问答
更多-
而不是使用clock()来测量时间,你应该事件: 使用事件你会有这样的事情: cudaEvent_t start, stop; // variables that holds 2 events float time; // Variable that will hold the time cudaEventCreate(&start); // creating the event 1 cudaEventCreate(&stop); // crea ...
-
System.Buffer.BlockCopy更接近C的memcpy但仍有开销。 对于小案例,您自己的方法通常会更快,而对于大案例,BlockCopy会更快。 复制引用比复制int更慢,因为在分配引用时,.NET在大多数情况下必须做一些额外的工作 - 这个额外的工作与垃圾收集有关。 有关此事实的演示,请查看下面的代码,其中包含用于复制每个字符串元素的本机代码与复制每个int元素(本机代码在注释中)。 请注意,它实际上进行函数调用以将字符串引用分配给src [i],而int是内联完成的: static ...
-
为什么我们复制然后移动?(Why do we copy then move?)[2021-06-18]
在我回答你的问题之前,有一件事似乎是错误的:C ++ 11中的价值并不总是意味着复制。 如果一个rvalue被传递,那将被移动 (提供一个可行的移动构造函数存在),而不是被复制。 而std::string确实有一个移动构造函数。 与C ++ 03不同的是,在C ++ 11中,通常按惯例来取参数,原因如下。 另请参阅StackOverflow上的此问答,以获取有关如何接受参数的更为一般的指导方针。 为什么我们不采取rvalue参考str ? 因为这样就不可能传递左值,例如: std::string s = " ... -
复制但不能移动(Copy but not move)[2023-09-04]
是的,一个班级可以复制但不可移动是合法的: class MyClass { public: /* Copyable... */ MyClass(const MyClass&); MyClass& operator= (const MyClass&); /* ... but not movable. */ MyClass(MyClass&&) = delete; MyClass& operator= (MyClass&&) = delete; }; 然而,我 ... -
为什么nio.files.copy比nio.fileChannel复制要慢很多?(Why does nio.files.copy is a lot slower than nio.fileChannel copy?)[2024-03-31]
TL; DR - 这是缓存问题 在任务管理器中运行基准测试打开的“ 性能”选项卡时,您会看到差异来自哪里。 在Files.copy测试期间,您可能会看到高磁盘写入速度。 但是当transferTo测试运行时,磁盘将几乎空闲! 这意味着没有数据实际写入设备 - 复制在内存中执行。 这显然要快得多。 Java Files.copy方法是使用CopyFileEx WinAPI函数实现的。 没有明确规定CopyFileEx如何在内部工作,但是观察到它会做一些实际的磁盘I / O. 依次transferTo执行一系列 ... -
您可以在返回NSDragOperation时检查是否按下了ALT(Option)键。 例: if context == NSDraggingContext.OutsideApplication { return .None } else { // get the current global event object // and compare its modifier flags with ours if let event = NSApplication.shared ...
-
hadoop复制或移动(hadoop copy or move)[2023-12-09]
找到了我自己的问题的解决方案! 1. hadoop按目录获取所有日期并在本地保存。 例如 hadoop fs -get / warehouse / elephant / f_transactions_report / date = 2012-12 *〜/ elephant 2. Hadoop将所有本地保存的目录放回到新目的地。 例如 hadoop fs -put~ / elephant / warehouse / elephant / f_transactional_events / 目录结构将保持不变。 ... -
为什么复制比移动慢?(Why is copy slower than move?)[2023-03-18]
当你在同一个文件系统上创建一个文件时,系统只需要改变目录条目以反映你的重命名。 文件中的数据甚至没有被读取。 (相同的文件系统意味着:相同的目录或相同的目录树/同一个驱动器,前提是源目录和目标目录不会遍历导致另一个文件系统的符号链接!) 当你跨越文件系统创建一个文件时,它与cp + rm具有相同的效果:没有速度增益(除了你只运行一个命令并保证一致性的事实:你不必检查cp是否成功执行rm) (旧版本的mv拒绝在文件系统中移动目录,因为它们只做了重命名) 小心,它不等同。 默认情况下, cp覆盖目标,而mv将无 ... -
shutil.move()比os.remove()+ os.rename()慢(shutil.move() slower than os.remove() + os.rename())[2022-07-24]
如果src和dst在不同的文件系统上os.rename(src, dst)则无法保证os.rename(src, dst)正常工作。 如果dst存在,它在Windows上不起作用。 就像文档说的那样 There is no guarantee that os.rename(src, dst) works if src and dst are on different filesystems. And it does not work on Windows if dst exists. Just as the ... -
如名称所示,复制构造函数/赋值运算符应始终COPY而不移动其成员,其中复制通常表示深层复制。 记住:默认情况下,c ++中的所有对象都应该具有值语义,即它们应该像int 。 此外,帖子中的术语表明您将独特对象(单例)与unique_ptr指向的对象混淆。 大多数不可复制的对象都是处理程序(如unique_ptr处理堆上的对象),在这种情况下,您可以复制它们处理的任何内容。 如果那是不可能的,那么最有可能的是,实现对象的复制构造函数是没有意义的。 如果您的对象拥有对唯一资源的拥有引用(项目中只能有一个实例), ...